Search code examples
visual-studio-code

Can't launch VS Code from command prompt


I am trying to set up a local development environment for practicing C++. I have installed Visual Studio Code and Microsoft Visual Studio 2022, and the MSVC compiler. I was going through the steps outlined in the welcome guide in VS Code, but I cannot get VS Code to relaunch through the Developer Command Prompt with the 'code' command. The prompt gives back:

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

If it's at all related, I have VS Code installed on a different drive from C:. If there is anyone out there savvy with setting this up, I would really appreciate your insight. Thanks,

I tried running the 'code' command in the Developer Command Prompt for VS 2022, but I am getting the error:

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

I thought that perhaps it had something to do with not having a compiler set up, so I installed Microsoft Visual Studio Build Tools, and retried the command. It did not seem to have an effect.


Solution

    1. Find the Installation Path:

    Locate the directory where VS Code is installed. It should contain Code.exe. Common locations are: C:\Program Files\Microsoft VS Code\bin (default installation on C:) :\path\to\VS Code\bin (if installed on a different drive)

    1. Update System Environment Variables:

    Open the Start Menu and search for "Environment Variables". Select "Edit the system environment variables". In the System Properties window, click on the "Environment Variables" button. In the Environment Variables window, under "System variables", find and select the "Path" variable. Click "Edit". In the Edit Environment Variable window, click "New" and add the path to the VS Code bin directory. Click "OK" to close all dialogs.

    1. Restart Command Prompt:

    Close and reopen the Developer Command Prompt for VS 2022 and try the code command again.