How to Fix VS Code Error: "Code Command Not Found" When Launching from Terminal
Encountering the Code Command Not Found error when trying to launch Visual Studio Code (VS Code) from the terminal is a common problem, especially after a fresh installation or update.
This issue occurs because the terminal doesn’t recognize the code
command, which is used to open VS Code from the command line.
To resolve this, you need to ensure that the code
binary is properly added to your system's PATH.
Here’s a detailed step-by-step solution: First, check if the code
command is installed on your system.
Open VS Code, press Ctrl+Shift+P
(or Cmd+Shift+P
on macOS), and type Shell Command: Install 'code' command in PATH.
Select this option and restart your terminal.
If this doesn’t fix the issue, you may need to manually add VS Code to your PATH.
On macOS, locate the VS Code binary.
It’s usually located in /Applications/Visual Studio Code.app/Contents/Resources/app/bin
.
Add this directory to your PATH by editing your shell configuration file (e.g., .bashrc
, .zshrc
, or .bash_profile
).
For example, add export PATH=**/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH**
.
Save the file and run source ~/.zshrc
(or the relevant file) to apply the changes.
On Windows, the process is slightly different.
First, locate the installation directory for VS Code, typically C:\Users\<YourUsername>\AppData\Local\Programs\Microsoft VS Code\bin
.
Add this directory to the system PATH.
To do this, search for Environment Variables in the Start menu, open it, and under System variables, select Path and click Edit. Add the directory path to the list and save.
Restart your terminal or command prompt, and the code
command should now work.
On Linux, the steps are similar to macOS.
Locate the VS Code binary, which is often found in /usr/share/code/bin
.
Add this to your PATH by editing your .bashrc
or .zshrc
file.
Use the command export PATH=**/usr/share/code/bin:$PATH**
, save the file, and reload your shell using source ~/.bashrc
.
If none of these steps work, ensure you’re using the correct terminal or shell.
Some terminals require additional configuration to recognize updated PATH variables.
Also, verify that there are no conflicting applications named code
in your PATH.
Finally, if the issue persists, reinstall VS Code and follow these steps again.
This should resolve the error and allow you to launch VS Code seamlessly from the terminal.