Fix code . command not working | Visual Studio Code

Sh Raj - Apr 15 - - Dev Community

How to Reinstall Visual Studio Code on macOS Using Command Palette

Visual Studio Code is a popular code editor among developers for its versatility and extensive features. However, sometimes you might encounter issues with the code command not working in the terminal, especially after an update or if you've had a problematic installation. In this guide, we'll walk through the steps to reinstall Visual Studio Code on macOS using the Command Palette.

Step 1: Remove Previous Installation (if needed)

If you're experiencing issues with the code command, it might be due to a previous installation. Let's start by removing the existing code binary.

Open your terminal and run:

sudo rm /usr/local/bin/code
Enter fullscreen mode Exit fullscreen mode

This command removes the code binary from the /usr/local/bin directory.

Step 2: Reinstall Visual Studio Code

Now, open Visual Studio Code. Since the code command is missing, you won't be able to launch it from the terminal directly. Instead, we'll use the Command Palette within Visual Studio Code to set it up.

Step 3: Use Command Palette to Install 'code' Command

  1. Open Visual Studio Code.
  2. Press Ctrl + Shift + P (or Cmd + Shift + P on macOS) to open the Command Palette.
  3. Type Shell Command: Install 'code' command in PATH and select it when it appears in the list.

Command Palette

  1. Follow the instructions in the popup that appears. This will automatically set up the code command for you.

Step 4: Verify Installation

After completing these steps, you should be able to use code . in the terminal to open Visual Studio Code in the current directory. This method is very handy for setting up the code command without manually editing configuration files.

Additional Note for Users with Multiple Terminals

If you have more than one terminal installed (e.g., zsh, bash), you'll need to repeat the steps (Step 3 -> Point 3) above for each terminal you use. This ensures that the code command is available in all your terminal sessions.

Summary

In this guide, we've covered how to reinstall Visual Studio Code on macOS using the Command Palette. If you're encountering issues with the code command not working in the terminal, following these steps should help resolve the issue.

If you have any questions or encounter any difficulties during the process, feel free to ask in the comments below!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .