Code Command Not Found: How to Add VS Code to PATH

Fix the 'code' command not found error on macOS, Windows, and Linux. Learn to install the code shell command, add VS Code to PATH manually, and resolve PATH conflicts.

5 min read

The code command lets you open VS Code from the terminal. You can type code . to open the current folder, or code file.js to open a specific file. When the command is not found, VS Code is not on your system PATH. The fix depends on your operating system.

macOS: install the shell command

macOS has the simplest fix. VS Code includes a built-in command that adds itself to your PATH.

Open VS Code. Open the Command Palette with Cmd+Shift+P, type shell command, and run Shell Command: Install 'code' command in PATH.

You will see a confirmation that the command was installed. Close the terminal completely and open a new one. Run code --version to verify it works.

If you previously had an older version of VS Code and already ran this command, an old alias might conflict. Open your shell configuration file (~/.zshrc for Zsh, ~/.bash_profile for Bash) and remove any lines that reference an old VS Code path. Then run the Shell Command installer again.

Manual PATH setup on macOS

If the Command Palette method does not work, add the path manually. Add this line to your ~/.zshrc (Zsh) or ~/.bash_profile (Bash):

bashbash
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

Save the file, restart your terminal, and test with code --version.

Windows: check the installer option

On Windows, the VS Code installer adds the code command to your PATH by default. If it is not working, the option was likely deselected during installation.

Re-run the official VS Code installer. On the Select Additional Tasks screen, make sure Add to PATH is checked. Complete the installation without removing your settings.

If that does not work, add the bin folder manually. The location depends on your VS Code installation:

  • User installer: %LOCALAPPDATA%\Programs\Microsoft VS Code\bin
  • System installer: C:\Program Files\Microsoft VS Code\bin

Open Windows Settings, search for environment variables, and edit your User Path. Add the full existing bin directory for your installation; do not replace the current Path value. Click OK on all dialogs, then restart open terminals.

Also make sure your terminal application (PowerShell, Command Prompt, or Windows Terminal) was restarted after the PATH change. PATH changes only apply to new terminal sessions.

Linux: verify the package installation

When you install VS Code through the official package (DEB, RPM, Snap, or from the repository), the code command is added to your PATH automatically. If it is missing, the installation may be incomplete.

Reinstall with the same supported method for your distribution by following the official VS Code Linux setup. The repository setup differs between Debian-based, RPM-based, Snap, and other distributions, so do not run a package command copied for a different installation source.

After reinstalling, open a new terminal and run command -v code. A returned executable path confirms that the shell can resolve the command. For a guided platform installation, see how to install VS Code on Linux.

Verify the fix

After any of the fixes above, test the code command in a new terminal. Run:

bashbash
code --version

This prints the VS Code version, confirming the command is working. If you see a version number, the fix is complete.

You can now use common code commands. See the full VS Code command line interface guide for all available options:

  • code .: open the current folder in VS Code
  • code file.js: open a specific file
  • code --diff file1 file2: compare two files
  • code --goto file.js:10: open a file at a specific line

These commands and the platform PATH behavior are documented in the official VS Code command-line guide. If you use VS Code Insiders, test code-insiders --version instead; Insiders is a separate preview build.

Restart your terminal

PATH changes only take effect in new terminal sessions. After any fix, close your terminal completely and open a new one. A new tab might reuse an existing terminal process, so use a new window for this test.

Rune AI

Rune AI

Key Insights

  • On macOS, run Shell Command: Install 'code' command in PATH from the Command Palette.
  • On Windows, re-run the VS Code installer and check Add to PATH during setup.
  • On Linux, code is added to PATH automatically when installed via the official package.
  • After any PATH change, restart your terminal completely for it to take effect.
  • Check for old aliases that might override the code command.
RunePowered by Rune AI

Frequently Asked Questions

Why does the code command work in some terminals but not others?

Existing terminal processes keep the PATH they started with, and different shells can load different profile files. Close every affected terminal window and open a new one. If the problem remains, run type code on macOS or Linux, or Get-Command code on PowerShell, to see what that shell resolves.

I installed the code command but it still says not found. What else can I try?

Check whether an old alias or shell function overrides code. On macOS, remove an obsolete VS Code alias from the relevant shell profile, then run Shell Command: Install 'code' command in PATH again. On Windows or Linux, reinstall through the official platform method if the installation did not add the binary.

What command launches VS Code Insiders?

VS Code Insiders is a separate preview build and uses code-insiders. The code command belongs to VS Code Stable unless you deliberately configure a different alias.

Conclusion

Use VS Code's shell-command installer on macOS and the official installer or package setup on Windows and Linux. Open a new terminal and run code --version; a printed version confirms that PATH resolution works. VS Code Insiders remains separate under code-insiders.