Troubleshooting

zsh: command not found: code? Put VS Code's code command on your PATH

zsh: command not found: code means the VS Code launcher is not on PATH. Fix it on macOS, Windows, Linux and WSL, and what works over SSH on a VPS.

Published ~8 min read
On this page

Short answer

code is the small launcher script that ships inside Visual Studio Code. The editor can be installed and working while the launcher’s folder is not on your shell’s PATH, and then zsh: command not found: code is all you get. On a Mac run Shell Command: Install ‘code’ command in PATH from the Command Palette, on Windows reopen the terminal after setup, on Linux install the code package or snap. On a server you reach over SSH the command is not supposed to exist at all: use Remote-SSH from your own machine instead.

Where to start

Check what the shell can see

Before changing anything, ask the shell whether any code exists and where it looks. These lines work in bash and zsh and change nothing:

bash · zsh
command -v code            # path of the code this shell would run
type -a code               # every code on PATH, plus aliases and functions
echo "$PATH" | tr ':' '\n'  # the folders it searches, in order

No output from the first line means no folder on PATH holds a code. The wording of the error depends on the shell. On one of our Debian 12 servers, where VS Code is not installed, bash and sh answer like this and both exit with status 127:

output · Debian 12
$ bash -c 'code .'
bash: line 1: code: command not found
$ sh -c 'code .'
sh: 1: code: not found
$ echo $?
127

In an interactive bash the message reads bash: code: command not found, zsh on a Mac prints zsh: command not found: code, and Windows has two versions of its own:

Windows
# PowerShell
code : The term 'code' is not recognized as the name of a cmdlet, function, script file, or operable program.

# Command Prompt
'code' is not recognized as an internal or external command,
operable program or batch file.

All of these mean the same thing: the launcher is not in any folder on PATH. The general background, and how a PATH change becomes permanent in bash, zsh and fish, is in command not found: the three causes.

macOS: install the shell command

Dragging VS Code into Applications installs the editor, not the command. The launcher lives inside the app bundle at /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code, and nothing puts that folder on PATH until you ask for it:

  • Open VS Code and press Cmd+Shift+P for the Command Palette.
  • Type shell command and choose the install entry. Older releases call it Install ‘code’ command in PATH; Microsoft’s current setup page lists it as Install ‘code’ and optionally ‘copilot’ commands in PATH.
  • Open a new terminal window, or run rehash in zsh, and try code --version.

The palette entry needs permission to write its link. If you would rather not give it, or it fails, add the folder to PATH yourself. This is the line from Microsoft’s macOS setup page; the backslash keeps $PATH from being expanded while the line is written:

zsh (default on macOS)
cat << EOF >> ~/.zprofile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF

For bash use ~/.bash_profile instead of ~/.zprofile. Then open a new terminal. If type -a code shows an old alias called code from an earlier setup, delete that line from your profile; Microsoft’s page gives the same advice.

Installed with Homebrew? brew install --cask visual-studio-code links the launcher into Homebrew’s own bin folder, so code works as long as Homebrew is on PATH. If brew itself is not found, fix Homebrew’s PATH first.

Windows: the bin folder on PATH

The installer adds VS Code’s bin folder to PATH, and that folder holds code.cmd for PowerShell and Command Prompt and a code script for Git Bash. Where it sits depends on the installer:

Installerbin folder
User setup (the default download)%LOCALAPPDATA%\Programs\Microsoft VS Code\bin
System setup (needs admin)C:\Program Files\Microsoft VS Code\bin

The most common cause is a terminal that was already open during setup. A PATH change only reaches programs started after it, so close every terminal and open a new one. The terminal inside VS Code inherits the environment VS Code itself started with: quit VS Code completely and start it again. Then check:

PowerShell
Get-Command code              # where PowerShell finds it
where.exe code                # the same for cmd-style lookups
$env:Path -split ';' | Select-String 'VS Code'

If the folder is missing from PATH, the box Add to PATH was cleared during setup. Run the installer again and leave it ticked, or add the folder to your user PATH. For the user setup:

PowerShell · user PATH, no admin needed
$bin = "$env:LOCALAPPDATA\Programs\Microsoft VS Code\bin"
Test-Path "$bin\code.cmd"     # must say True
$user = [Environment]::GetEnvironmentVariable('Path', 'User')
[Environment]::SetEnvironmentVariable('Path', "$user;$bin", 'User')

Open a new terminal afterwards. Installing with winget install -e --id Microsoft.VisualStudioCode runs the same installer, so the same rule about reopening the terminal applies.

Linux desktop: package, snap, Flatpak or tarball

On Linux the answer depends on how VS Code got onto the machine:

Installed withcode commandIf it is not found
Microsoft’s .deb or .rpm, or their apt or dnf repository/usr/bin/codeCheck that the package is installed: dpkg -l code or rpm -q code
sudo snap install --classic code/snap/bin/code/snap/bin is missing from PATH: log out and back in once after installing snapd
Flatpak (com.visualstudio.code, a community package)noneUse flatpak run com.visualstudio.code, or an alias
The .tar.gz archivebin/code inside the unpacked folderAdd that bin folder to PATH yourself

The snap case catches people on Debian and on minimal Ubuntu installs: snapd puts /snap/bin on PATH through a script in /etc/profile.d, which only login shells read. A new login fixes it. For Flatpak and the archive, two lines in ~/.bashrc or ~/.zshrc do the job:

~/.bashrc or ~/.zshrc
# Flatpak: make 'code' start the Flatpak build
alias code='flatpak run com.visualstudio.code'

# tar.gz: put the archive's bin folder on PATH (adjust the path)
export PATH="$PATH:$HOME/opt/VSCode-linux-x64/bin"

Then source ~/.bashrc or open a new terminal. The same PATH rules apply to every other program, see how to set environment variables on Linux.

WSL: code . needs the Windows side

Inside WSL, code . does not run a Linux copy of VS Code. It calls the Windows install, which opens a window connected to WSL through the WSL extension and sets up the VS Code Server in your Linux home on first use. That only works because WSL appends the Windows PATH to the Linux one; Microsoft’s troubleshooting page puts it as paths being inherited from the PATH variable in Windows.

So check the Windows side first: VS Code installed on Windows, and code working in PowerShell. If it does and WSL still says command not found, the inheritance is probably switched off in /etc/wsl.conf:

/etc/wsl.conf
[interop]
appendWindowsPath = true   # false hides every Windows program, code included

Change it, run wsl --shutdown in PowerShell and open WSL again. If you keep appendWindowsPath off on purpose, add only the VS Code folder:

~/.bashrc in WSL
export PATH="$PATH:/mnt/c/Users/YOUR_WINDOWS_NAME/AppData/Local/Programs/Microsoft VS Code/bin"

On a VPS over SSH: code is not supposed to be there

A frequent version of this error: you log in to a server with ssh, type code . out of habit and get bash: code: command not found. On a headless server that is correct. VS Code is a desktop program, and installing the desktop package on a VPS pulls in graphical libraries without giving you a window to look at.

The working setup runs the other way round:

  • Install the Remote-SSH extension in VS Code on your own computer and connect to user@your-server. A Host entry in ~/.ssh/config turns that into one click, see the SSH config file.
  • On first connect VS Code installs its server part on the VPS, under ~/.vscode-server. The editor window stays on your machine; files, terminals and extensions run on the server.
  • In the terminal inside that window, code somefile works: the server provides its own code helper there, and it opens the file in your local window.
  • In a separate plain ssh session the same command stays unknown, because that helper belongs to the VS Code session. That is expected, not a broken install.

The server needs very little: Microsoft lists glibc 2.28 or newer, which means Ubuntu 20.04 and later or Debian 10 and later, plus a running OpenSSH server and bash. If Remote-SSH cannot connect at all, try a plain ssh user@your-server from a terminal first: if that fails too, the problem is SSH itself, not code.

Without an SSH login: code tunnel

Microsoft also publishes a standalone VS Code CLI for Linux, a single binary also named code, on the VS Code download page. Run ./code tunnel on the server, sign in when it asks, and you can open that machine from VS Code or vscode.dev without an open SSH port. That binary is a separate download; it is not what the desktop launcher gives you.

Insiders, VSCodium and Cursor use other names

Builds that are not stable VS Code install a launcher under their own name, so code stays unknown even when everything is set up correctly:

EditorCommand
Visual Studio Codecode
VS Code Insiderscode-insiders
VSCodiumcodium
Cursorcursor

Each of them has its own install-in-PATH entry in its Command Palette on macOS. If a script or a tutorial insists on code, an alias such as alias code=codium in your shell profile is enough.

code is found but opens the wrong thing

type -a code lists every match in PATH order. Two common surprises: an old alias from an earlier setup that points at an app that no longer exists, and two installs at once (say the snap and the .deb), where the first folder on PATH wins. Remove the alias or the install you do not use, then run hash -r in bash or rehash in zsh so the shell forgets the old location.

Want a server to try Remote-SSH on? Our Standard KVM plans run Ubuntu or Debian with full root access, which is everything the VS Code Server needs.

How we tested

OS image
Debian 12 (bookworm)
Versions
GNU bash 5.2.15dash (/bin/sh)
Tested on
Where
One of our own Debian 12 servers, without VS Code
Method
Only the not-found messages of bash and sh and exit status 127 were run as shown; nothing was installed
From vendor sources, not run
VS Code setup pages for macOS, Windows and Linux, Remote Development with Linux and Remote troubleshooting (code.visualstudio.com, read 2026-11-08), WSL interop settings, Homebrew cask, Flatpak package name, the editors' launcher names

Frequently asked

Why does zsh say command not found: code on my Mac?

Installing VS Code does not put its launcher on PATH. Open the Command Palette with Cmd+Shift+P, search for shell command and run the entry that installs the code command in PATH, then open a new terminal. Move the app into Applications first, because the command links to wherever the app sits at that moment.

How do I fix 'code' is not recognized on Windows?

Close every terminal and open a new one, and restart VS Code if you used its built-in terminal: a PATH change only reaches programs started after it. If it still fails, the bin folder is missing from PATH. For the user setup that is %LOCALAPPDATA%\Programs\Microsoft VS Code\bin; rerun the installer with Add to PATH ticked or add the folder to your user PATH.

Why does code . not work in WSL?

In WSL the code command is the Windows install, found through the Windows PATH that WSL appends to the Linux one. Make sure code works in PowerShell first. If it does, check /etc/wsl.conf: appendWindowsPath = false under [interop] hides it. Set it to true and run wsl --shutdown, or add the VS Code bin folder under /mnt/c to PATH.

Should I install VS Code on my VPS to use the code command?

No. On a headless server use the Remote-SSH extension from VS Code on your own computer. It installs the VS Code Server under ~/.vscode-server on the VPS, and in that window's terminal code somefile opens the file locally. In a plain ssh session code stays unknown, which is expected. The server needs glibc 2.28 or newer, such as Ubuntu 20.04+ or Debian 10+.

Related articles

All troubleshooting