How to Fix the “zsh: command not found: code” Error in macOS Terminal

How to Fix the “zsh: command not found: code” Error in macOS Terminal

The quickest way to open a folder in VS Code is by using the code command in Terminal. But if you haven’t configured it correctly, you might encounter a “zsh: command not found: code” error. Follow these two steps to fix it.

1. Reinstall Visual Studio Code

Usually, the recommended way to install software on a Mac is via the App Store. However, since VS Code isn’t available on the App Store, downloading it from Visual Studio Code’s official site is your only option.

Even if you did that already, you might still be running the app from the Downloads folder in macOS. So make sure you move the executable file to the Applications folder instead.

2. Install the Code Command to PATH Variables

After moving VS Code to your Applications folder, you must add the code command to your PATH variables. Once the command is in your PATH environment variables, you can run it from the Terminal app in macOS.

Luckily, you don’t have to fiddle with the command line to do so. VS Code provides a one-click solution to add the command to your PATH variables, by doing the following:

  1. Open VS Code on your Mac.
  2. Press Cmd + Shift + P to open the Command Palette.
  3. Now, type Shell Command. From the displayed results, select Install ‘code’ command in PATH.How to Fix the “zsh: command not found: code” Error in macOS Terminal
  4. Next, VS Code will ask for permission to install the code command. Select OK.
  5. Enter your Mac’s admin password in the follow-up prompt and press OK.Code command installation confirmation dialog

Once done, a “Shell command ‘code’ successfully installed in PATH” dialog will appear. Now, even if you don’t know your way around the Mac Terminal, you can quickly open a folder in macOS by using the code command. Just open Terminal on your Mac and navigate to the folder using the cd command. Once you’re in the folder of interest, enter “code .” in Terminal and press Return (or Enter).

As one of the best free code editors, VS Code provides a wide array of features that make it easy to develop and debug software. If you prefer using Terminal to navigate your file system, the code command makes it easy to open the current folder in the editor.