How to Set Up code . Command in Mac to Open VSCode

Jay KumarJay Kumar
3 min read

Visual Studio Code (VSCode) is a popular code editor that offers a variety of powerful features for developers. One of the convenient features is the ability to open VSCode from the terminal using the code . command. This allows you to quickly open the current directory in VSCode without navigating through the graphical interface. If you're a Mac user, setting this up is straightforward. Here's a step-by-step guide on how to do it.

Step 1: Install Visual Studio Code

If you haven't already, you'll need to install Visual Studio Code on your Mac. You can download it from the official VSCode website.

  1. Go to the VSCode download page.

  2. Click on the download button for macOS.

  3. Once downloaded, open the .dmg file and drag VSCode to the Applications folder.

Step 2: Open Visual Studio Code

After installing VSCode, open it from your Applications folder or by searching for it in Spotlight.

Step 3: Open Command Palette

The Command Palette in VSCode is a powerful tool that allows you to execute various commands. To open it, you can use the keyboard shortcut:

Command (⌘) + Shift + P

Alternatively, you can go to the menu bar at the top and select View -> Command Palette....

Step 4: Install 'code' Command in PATH

With the Command Palette open, type the following to find the command to install code in PATH:

Shell Command: Install 'code' command in PATH

Select this option by pressing Enter.

What this does is it creates a symbolic link to the code command in /usr/local/bin, which is included in your PATH by default on macOS.

Step 5: Verify Installation

To ensure that the code command is installed correctly, open your terminal (you can use the built-in Terminal app on your Mac) and type:

code --version

If the installation was successful, this command should return the version number of your VSCode installation.

Step 6: Open VSCode with code .

Now that you have the code command set up, you can use it to open any directory in VSCode. Navigate to the directory you want to open in VSCode using the cd command. For example:

cd /path/to/your/project

Once you’re in the desired directory, simply type:

code .

This command will open the current directory in VSCode, making it easy to start coding right away.

Troubleshooting

If you encounter any issues, here are a few troubleshooting steps:

  1. Command Not Found Error: Ensure that /usr/local/bin is in your PATH. You can check this by running echo $PATH in your terminal. If it’s not, you can add it by editing your shell configuration file (e.g., .bash_profile, .zshrc).

  2. Permission Issues: If you encounter permission issues when installing the code command, try running the Command Palette command as an administrator by prefixing it with sudo.

  3. Updating VSCode: Sometimes updates to VSCode might remove the code command. If this happens, simply repeat the installation steps from Step 3.

Conclusion

Setting up the code . command on your Mac to open VSCode is a simple process that can greatly enhance your workflow. With just a few steps, you can quickly open your projects in VSCode directly from the terminal, making it easier to jump into coding without the hassle of navigating through directories manually. Happy coding!

If you have any questions or run into any issues, feel free to leave a comment below.

10
Subscribe to my newsletter

Read articles from Jay Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jay Kumar
Jay Kumar

Jay Kumar is a proficient JavaScript and Node.js developer with 7 years of experience in building dynamic and scalable web applications. With a deep understanding of modern web technologies, Jay excels at creating efficient and innovative solutions. He enjoys sharing his knowledge through blogging, helping fellow developers stay updated with the latest trends and best practices in the industry.