Last updated: Apr 6, 2024
Reading time·6 min
Note: if you got the 'code' is not recognized as an internal or external command error on Windows, click on the second subheading.
The error "code: command not found" occurs for multiple reasons:
Applications
folder on macOS.The error most commonly occurs when you try to issue the code .
command in
bash
or zsh
on macOS, Linux or Windows.
The first thing you need to verify is that you have Visual Studio Code installed.
Visit the official Download Visual Studio Code page and download the installer for your operating system.
Run the installer and complete the process.
Here are the official installation instructions for the 3 operating systems:
Note: if you are on Linux, the easiest way to install VS Code is to use snap
.
# for Linux sudo snap install --classic code
The Snap daemon takes care of automatically updating VS Code in the background and sets everything up for you.
If you are on macOS, make sure to drag VS Code into your Applications
directory.
You most likely downloaded VS Code to
your Downloads
directory.
If you downloaded an archive, extract its contents.
Make sure to drag and drop the Visual Studio Code.app file from the Downloads directory to the Applications directory.
This will make VS Code available in the macOS Launchpad.
This subheading only applies to macOS.
code .
command).On macOS, you can double-click on the VS Code icon in the Applications folder.
Command
+ Shift
+ P
(⌘
+ Shift
+ P
) on macOS.Ctrl
+ Shift
+ P
on Windows.F1
to open the Command Palette.The next step is to Install 'code' in PATH.
Press:
Command
+ Shift
+ P
(⌘
+ Shift
+ P
) on macOS.Ctrl
+ Shift
+ P
on Windows.F1
to open the Command Palette.Note that you won't be able to issue the code .
command until all instances of
the terminal (bash
or zsh
) are fully restarted.
code .
command.code .
The .
in the command represents the current folder.
The command opens a Visual Studio Code instance in the current working directory.
You can use the pwd
command if you need to print the current working directory
of your terminal.
The following subheading only applies if you are on macOS.
If the error persists, try to add VS Code to your PATH environment variable manually.
Open your terminal and issue the following command.
echo $0 # or echo $SHELL
The command will print your default shell (e.g. bash
or zsh
).
If your default shell is bash
, issue the following commands from your
terminal.
# macOS with bash cat << EOF >> ~/.bash_profile # Add Visual Studio Code (code) export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin" EOF
If your default shell is zsh
, issue the following commands from your terminal.
cat << EOF >> ~/.zprofile # Add Visual Studio Code (code) export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin" EOF
Close your terminal and reopen it for the PATH environment variable to get updated.
You can also source
your config file.
# for bash source ~/.bashrc source ~/.bash_profile # for zsh source ~/.zshrc source ~/.zprofile
Open your terminal in your project's root directory and issue the code .
command.
code .
As previously noted, if you are on Linux, the easiest way to install VS Code is
to use snap
.
# for Linux sudo snap install --classic code
The Snap daemon takes care of automatically updating VS Code in the background and sets everything up for you.
Alternatively, you can view the installation instructions for all Linux flavors in this section of the official docs.
Make sure you are issuing the correct code
command.
If you installed the regular Visual Studio Code version, then the command is
code .
.
code .
If you installed VS Code from the OSS repository, then the command is
code-oss .
.
code-oss .
If you installed the insider's VS Code build, then the command is
code-insiders .
.
code-insiders .
To solve the "code: command not found", make sure:
code .
command.The error "'code' is not recognized as an internal or external command, operable program or batch file" occurs when Visual Studio code is not installed or added to your PATH environment variable.
To solve the error, install VSCode and add it to PATH.
The easiest way to solve the error is to use the VSCode installer, even if you have Visual Studio code installed.
code .
command.code .
Make sure to restart your CMD shell before issuing the code .
command.
PATH
environment variable won't be up to date.If you get a permissions error, run cmd
as an administrator before issuing the
code .
command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
Click on the Search bar and type "Visual Studio Code".
Right-click on the Visual Studio Code application and click "Open file location".
By default, VS Code is installed under the following path.
C:\Users\{Username}\AppData\Local\Programs\Microsoft VS Code
Click on "OK" twice to confirm the changes.
Close your Command prompt application and then reopen it.
You might also have to restart your PC, but that's not always necessary.
code .
command.code .
Make sure you are issuing the correct code
command.
If you installed the regular Visual Studio Code version, then the command is
code .
.
code .
If you installed VS Code from the OSS repository, then the command is
code-oss .
.
code-oss .
If you installed the insider's VS Code build, then the command is
code-insiders .
.
code-insiders .
If the error is not resolved, restart your PC before issuing the code .
command.
Restarting your PC ensures that the PATH environment variable is up-to-date.