Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Fix “zsh: command not found: code” on macOS

Add Visual Studio Code's code command to the macOS PATH, verify the installation, and fix stale Terminal sessions or conflicting aliases.

Table of Contents

The error zsh: command not found: code means Terminal cannot find Visual Studio Code's command-line launcher in the current PATH. You normally do not need to reinstall VS Code. Install the launcher from VS Code's Command Palette, restart Terminal, and verify it with command -v code.

Install the code command in PATH

  1. Make sure Visual Studio Code.app is in the Mac's Applications folder. If it is still in Downloads, move it before continuing.
  2. Open Visual Studio Code.
  3. Press Command-Shift-P to open the Command Palette.
  4. Type shell command, then select Shell Command: Install 'code' command in PATH.

Installing the code command from the VS Code Command Palette

  1. Approve the change and enter an administrator password if macOS requests it.

Authorizing the VS Code code command installation

  1. Quit every open Terminal window, start Terminal again, and run:
command -v code
code --version

The first command should print the launcher's path, and the second should print version information. Microsoft's official VS Code setup guide for macOS documents the same Command Palette method.

Open a folder in VS Code

Move to a project folder and run code .. The dot represents the current directory.

cd "/path/to/project"
code .

You can also open a specific file with code filename.txt or reuse the current VS Code window with code -r ..

If the command is still not found

1. Start a new shell session

An existing Terminal window may still have the old environment. Open a new window or run:

exec zsh

Then test command -v code again.

2. Confirm the app is in Applications

The standard launcher path assumes this location:

/Applications/Visual Studio Code.app

If you renamed the app or keep it in another folder, move it to Applications and rerun Shell Command: Install 'code' command in PATH.

3. Remove a stale alias or old launcher

Check everything the shell can find under the name code:

type -a code

If the output points to an old alias or a missing file configured in ~/.zprofile, ~/.zshrc, or an older Bash profile, remove that outdated line. Restart Terminal, then install the launcher again from VS Code.

4. Add the VS Code bin folder manually

If the Command Palette action is unavailable, open ~/.zprofile in a text editor and add this line:

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

Save the file, then load it in the current shell:

source ~/.zprofile
command -v code

Do not replace the rest of your PATH; the $PATH: portion keeps its existing entries.

Other useful checks

  • VS Code Insiders: its command is normally code-insiders, not code.
  • Command works in one terminal only: compare the shell and startup files used by each terminal app.
  • Permission error during installation: confirm you are using an administrator account, then rerun the Command Palette action.
  • Wrong application: download VS Code from its official site and verify the app name before adjusting the path.

Once the launcher works, these VS Code extensions can add language and workflow features. If you are comparing editors, see this list of free code editors.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.