How to fix code. command not working | Visual Studio Code with the Terminal

Abhishek Singh
3 min readOct 15, 2023

While I was in the midst of work, I encountered a problem while attempting to establish a connection between my terminal and Visual Studio Code. Every time I tried to execute the ‘code .’ command from the terminal to open a directory in VS Code, I encountered a ‘command not found’ error. This brief vlog is dedicated to this specific issue and how I successfully resolved it. Let’s get started.

Problem screenshot

Solution :

Self-verified

Linking the “code” command with Visual Studio Code (VSCode) typically involves ensuring that the “code” command is recognized and properly configured in your system’s PATH. Here’s how you can link the “code” command to VSCode:

On macOS:

  1. Open VSCode: Launch Visual Studio Code if it’s not already open.
  2. Install Shell Command: In the top menu, click on “View” and select “Command Palette” or use the keyboard shortcut (Cmd+Shift+P). In the command palette, type "Shell Command" and select "Shell Command: Install 'code' command in PATH."
  3. Confirm Installation: You should see a message confirming the installation of the “code” command in your PATH. This allows you to use the “code” command in your terminal.

On Windows:

  1. Open VSCode: Launch Visual Studio Code if it’s not already open.
  2. Open the Command Palette: Press Ctrl+Shift+P to open the command palette.
  3. Type “Shell Command”: In the command palette, type “Shell Command” and select “Shell Command: Install ‘code’ command in PATH.”
  4. Confirm Installation: You should see a message confirming the installation of the “code” command in your PATH. This allows you to use the “code” command in your terminal.

On Linux:

  1. Open VSCode: Launch Visual Studio Code if it’s not already open.
  2. Open the Command Palette: Press Ctrl+Shift+P to open the command palette.
  3. Type “Shell Command”: In the command palette, type “Shell Command” and select “Shell Command: Install ‘code’ command in PATH.”
  4. Confirm Installation: You should see a message confirming the installation of the “code” command in your PATH. This allows you to use the “code” command in your terminal.

Lets Perform this Step one by one

I will directly attach screenshot

That’s it.

Simple hack and it will save lots of time in your coding journey.

After performing these steps, you should be able to use the “code” command in your terminal or command prompt to open files and directories in Visual Studio Code. For example, you can use the following command to open the current directory in VSCode:

code .

If you encounter any issues, ensure that VSCode is correctly installed and that you have administrative privileges to make changes to your system’s PATH.

Codehippo.co.uk has compiled a selection of other valuable and fundamental Linux commands that can aid in your learning journey

Happy coding

Abhishek Singh

--

--

Abhishek Singh

Developer at policy advisor, Find me as @abhishekthatguy | Ex-Accenture || Ex-Rapidian || Web Development || Devops || Vue || React