Visual Studio Code from Your Terminal (Mac)
Discover a simple and effective way to enhance your productivity with Visual Studio Code on macOS. In this tutorial, we'll walk you through the process of adding the VSCode executable to your system's PATH, making it easy to access the code command from the terminal at any time—even after system restarts. Say goodbye to navigating through menus and hello to a faster, more efficient workflow. Get started now and elevate your coding experience to the next level!
To open Visual Studio Code (VSCode) on a Mac via the command line, follow these steps:
-
First, ensure that Visual Studio Code is installed on your Mac. If it's not installed, download it from the official website: https://code.visualstudio.com/download
-
Open Terminal (you can find it in Applications > Utilities, or by using Spotlight Search and typing "Terminal").
-
Add Visual Studio Code to your system's PATH. This will allow you to access the
codecommand from anywhere in the Terminal.To add VSCode to your system's PATH, run the following command in Terminal:
echo 'export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"' >> ~/.zshrcIf you are using an older version of macOS that uses the Bash shell instead of Zsh, use this command instead:
echo 'export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"' >> ~/.bash_profile -
Restart your Terminal, or open a new Terminal window, for the changes to take effect.
-
Now, you can open Visual Studio Code from the command line by simply typing
codefollowed by the directory or file you want to open. For example:code .This command will open the current working directory in VSCode.
If you want to open a specific file, use the file's path, like this:
code /path/to/your/fileThis command will open the specified file in VSCode.
From now on, you can use the code command in Terminal to open Visual Studio Code quickly and easily.
Note
echo 'export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"' >> ~/.zshrc
This command appends the export PATH line to your ~/.zshrc file, making the change persistent. The ~/.zshrc file is a configuration file for the Zsh shell that is executed every time you open a new terminal window or start a new terminal session. By adding this line to the file, you are ensuring that the code command will be available in your terminal sessions even after a system restart.
To apply the changes, you need to either restart the terminal or open a new terminal window. This is because the changes are only applied when a new terminal session starts and loads the configuration files.
From that point forward, you can access Visual Studio Code using the code command in the terminal, even after restarting your computer.