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

Encountering the “zsh: command not found: code” error in the macOS Terminal can be a frustrating roadblock when attempting to quickly open a folder in Visual Studio Code.

While the “code” command provides a convenient shortcut, it needs to be properly configured to work seamlessly. In this article, we’ll guide you through two straightforward steps to resolve this issue and streamline your workflow.

Step 1: Reinstall Visual Studio Code

The recommended approach to installing software on a Mac is typically through the App Store. However, since Visual Studio Code is not available on the App Store, you’ll need to download it from the official Visual Studio Code website. Even if you’ve already done this, ensure that you’ve moved the executable file from the Downloads folder to the Applications folder.

Read: How to properly clean reinstall your MacOS

Step 2: Install the Code Command to PATH Variables

After moving Visual Studio Code to your Applications folder, you must add the “code” command to your PATH environment variables. This step allows you to run the command from the Terminal app in macOS. Fortunately, Visual Studio Code provides a one-click solution to simplify this process:

1. Open Visual Studio Code on your Mac.

2. To open the Command Palette, press Cmd + Shift + P.

3. Type “Shell Command” and select “Install ‘code’ command in PATH” from the displayed results.

4. When prompted, grant permission for Visual Studio Code to install the “code” command.

5. Enter your Mac’s admin password in the follow-up prompt and press OK.

Once this process is complete, a “Shell command ‘code’ successfully installed in PATH” dialog will appear, confirming the successful installation.

Now, even if you’re unfamiliar with the macOS Terminal, you can quickly open a folder by utilizing the “code” command. Simply open the Terminal, navigate to the desired folder using the “cd” command, and then enter “code .” followed by pressing Return (or Enter).

By following these two straightforward steps – ensuring a proper Visual Studio Code installation and adding the “code” command to your PATH variables – you can bid farewell to the “zsh: command not found: code” error and enjoy a streamlined workflow in the macOS Terminal.

 


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Nikolaus Oosterhof

Nikolaus holds a degree in software development and has a strong passion for all things tech-related, especially gadgets with screens. Though he is nostalgic for older phone models, he's a retired gamer and continues to enjoy programming in open-source environments. Additionally, Nikolaus enjoys writing about Linux, macOS and Windows and has experience designing web pages.

Leave a Reply