code command not found Visual Studio Code Error [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
6 min

banner

# Table of Contents

  1. code: command not found Visual Studio Code Error
  2. 'code' is not recognized as an internal or external command

Note: if you got the 'code' is not recognized as an internal or external command error on Windows, click on the second subheading.

# code: command not found Visual Studio Code Error

The error "code: command not found" occurs for multiple reasons:

  • Not having Visual Studio Code installed.
  • Not having VS Code in your PATH environment variable.
  • Forgetting to drag VS Code to the 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.

# Make sure you have VS Code installed

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.

shell
# for Linux sudo snap install --classic code

linux install vscode using snap

The Snap daemon takes care of automatically updating VS Code in the background and sets everything up for you.

# Drag VS Code into your Applications directory on macOS

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.

# Add VS Code to your PATH environment variable on macOS

This subheading only applies to macOS.

  1. Start Visual Studio Code (from the applications list if you aren't able to use the code . command).

On macOS, you can double-click on the VS Code icon in the Applications folder.

  1. Press:
  • Command + Shift + P ( + Shift + P) on macOS.
  • Ctrl + Shift + P on Windows.
Note: you can also press F1 to open the Command Palette.
  1. Type shell command and select Shell Command: Uninstall 'code' command from PATH.

uninstall code command from path

  1. The next step is to Install 'code' in PATH.

  2. Press:

  • Command + Shift + P ( + Shift + P) on macOS.
  • Ctrl + Shift + P on Windows.
Note: you can also press F1 to open the Command Palette.
  1. Type shell command and select Shell Command: Install 'code' command in PATH.

install code command in path

  1. Close all instances of your terminal for the PATH environment variable to get updated.

Note that you won't be able to issue the code . command until all instances of the terminal (bash or zsh) are fully restarted.

  1. Open your terminal in your project's root directory and try to issue the code . command.
shell
code .

issue code command

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.

print current working terminal directory

If the error persists, try restarting your PC for the PATH environment variable to get updated.

# Adding VS Code to your PATH on macOS manually

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.

shell
echo $0 # or echo $SHELL

print default 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.

shell
# 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.

shell
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.

shell
# 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.

shell
code .

# Installing and configuring VS Code on Linux

As previously noted, if you are on Linux, the easiest way to install VS Code is to use snap.

shell
# for Linux sudo snap install --classic code

linux install vscode using snap

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.

# Issuing the correct code command

Make sure you are issuing the correct code command.

If you installed the regular Visual Studio Code version, then the command is code ..

shell
code .

If you installed VS Code from the OSS repository, then the command is code-oss ..

shell
code-oss .

If you installed the insider's VS Code build, then the command is code-insiders ..

shell
code-insiders .

# Conclusion

To solve the "code: command not found", make sure:

  1. Visual Studio Code is installed on your machine.
  2. VS Code is added to your PATH environment variable.
  3. You have restarted your terminal before issuing the code . command.

# 'code' is not recognized as an internal or external 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.

code is not recognized as internal or external command

The easiest way to solve the error is to use the VSCode installer, even if you have Visual Studio code installed.

  1. Open the Visual Studio Code Downloads page and click on "Windows".

download windows vscode installer

  1. Accept the license agreement and click "Next".

vscode-accept-license-agreement

  1. Leave the default Destination location selected and click "Next".

vscode select destination location

  1. Leave the default Start Menu Folder selected and click "Next".

vscode select start menu folder

  1. Make sure you have the "Add to PATH (requires shell restart)" option ticked and click "Next".

vscode setup additional tasks

  1. Click on the "Install" button.

vscode click install

  1. Close your CMD shell, reopen it, navigate to your project's directory and issue the code . command.
cmd
code .

open-vscode-in-folder

Make sure to restart your CMD shell before issuing the code . command.

If you don't restart your shell, the 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:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

If you still get the "code is not recognized as an internal or external command error", you have to manually add Visual Studio Code to your PATH environment variable.
  1. Click on the Search bar and type "Visual Studio Code".

  2. Right-click on the Visual Studio Code application and click "Open file location".

search visual studio code

  1. Select the location of the Visual Studio Code executable and copy it.

copy vscode location in explorer

  1. Click on the Search bar, type "environment variables" and then click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "System variables" section, select the "Path" variable and click "Edit".

select path and click edit

  1. Click "New" and paste the path to the Visual Studio Code executable that you previously copied.

click new and paste path

By default, VS Code is installed under the following path.

cmd
C:\Users\{Username}\AppData\Local\Programs\Microsoft VS Code
  1. Click on "OK" twice to confirm the changes.

  2. Close your Command prompt application and then reopen it.

Note that you must restart your Command prompt shell for the changes to take effect.

You might also have to restart your PC, but that's not always necessary.

  1. Navigate to your project's directory and issue the code . command.
cmd
code .

open-vscode-in-folder

# Issuing the correct code command

Make sure you are issuing the correct code command.

If you installed the regular Visual Studio Code version, then the command is code ..

shell
code .

If you installed VS Code from the OSS repository, then the command is code-oss ..

shell
code-oss .

If you installed the insider's VS Code build, then the command is code-insiders ..

shell
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.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.