Nikhil
Nikhil

Reputation: 3950

The VSCode `code .` command is not working in the terminal/command prompt in Windows

this is the line i get when i did shell command in VS code

I get this error:

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

Morevoer, shell commands are not coming in my compiler VS code neither do setx path "%path%;C:\Program Files\Microsoft VS Code" is working in command prompt .

Upvotes: 21

Views: 82327

Answers (12)

Uziel Torres
Uziel Torres

Reputation: 1

If adding the bin to the Windows PATH and reinstalling VScode does not work, try the following method which worked for me:

  • Go to Windows Registry Editor
  • Go to HKEY_CURRENT_USER -> Software -> Windows -> Command Processor
  • Delete the value inside the AutoRun key, usually an if

Image

This method works for any command that when used does nothing, not even an error.

Upvotes: 0

Gabriel Staples
Gabriel Staples

Reputation: 52449

Adding the code executable to your PATH for use in the Git Bash or MSYS2 terminals

If you're trying to run the code command in Windows in a Git Bash (from Git for Windows) terminal, or in an MSYS2 terminal, and VSCode is installed, then you may just need to add the code executable to your PATH.

Here's how: from my MSYS2 setup answer here:

  1. Install VSCode and add the code executable into your PATH:

    Install VSCode from here, if you don't already have it: https://code.visualstudio.com/

    The code executable is found in the "$HOME/AppData/Local/Programs/Microsoft VS Code/bin" dir.

    Add it to your PATH by adding this line to the bottom of your ~/.bashrc file:

    DIR="$HOME/AppData/Local/Programs/Microsoft VS Code/bin"
    if [ -d "$DIR" ] ; then
        PATH="$DIR:$PATH"
    fi
    

    Close and re-open all terminals, or run . ~/.profile [or ~/.bashrc] in each one to re-source your ~/.profile and ~/.bashrc files.

    Now run code . in a terminal and it will open up a new instance of VSCode in your current directory. Now we're rockin'.

Upvotes: 1

Kevin Nzioka
Kevin Nzioka

Reputation: 925

Just adding here since the above answers did not work for me. On windows ten when updating the path do not add the /bin. So the added pat should be C:\Users\{user_name}\AppData\Local\Programs\Microsoft VS Code\

Upvotes: 0

GoodGuyGregory
GoodGuyGregory

Reputation: 61

I recently had to modify the path from /bin to /_

this is what I used after clicking the edit path variables section and it worked.

C:\Users\{user_name}\AppData\Local\Programs\Microsoft VS Code\_

make sure the path variable refers to the location of the .exe

Upvotes: 1

KyleMit
KyleMit

Reputation: 29829

For Windows OS

For Windows, you'll need to re-install code. You can download the latest version and just install it overtop of your existing install.

During setup, make sure to check the box to Add to PATH

Setup - Add to Path

See Also: The VSCode docs on installing the CLI

Upvotes: 2

nativelectronic
nativelectronic

Reputation: 862

about linux, if u can't see the >shell option with ctrl+shif+p, You could install via

sudo snap install --classic code

and try again

code .

Upvotes: 0

starryknight
starryknight

Reputation: 249

For Mac OS, You can paste this into your terminal, or in your .bashrc file (or whatever shell config file you are using) :

export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

Upvotes: 22

Nikhil
Nikhil

Reputation: 3950

I found it. In the "search" type environment variables then click on the "edit system environment variables".

Inside Environment variables->Path put C:\Users\{your_username}\AppData\Local\Programs\Microsoft VS Code\bin.

Go to the project folder and open the cmd with it typing in the location bar and then type code .

That will do.

Upvotes: 8

arunlazer
arunlazer

Reputation: 41

make sure you run the command in C folder

Then click window key + R and type rundll32.exe sysdm.cpl,EditEnvironmentVariables then enter . It will open Environment Variables edit Path variable . Check whether you have C:\Users\{pc name}\AppData\Local\Programs\Microsoft VS Code\bin if not add it and run code -v in C folder cmd

This worked for me !

Upvotes: 3

Vibha
Vibha

Reputation: 1109

After installation, you need to restart your computer to make the PATH changes effective. Post restart, the command worked for me.

Upvotes: 0

Tomasz Krasuski
Tomasz Krasuski

Reputation: 21

in windows problem is with insiders version of VSC. You can use 'code-insiders .' command or make a copy of 'code-insiders.cmd' file as 'code.cmd' inside folder with code-insider (use 'path' command to see where your VSC is installed)

Upvotes: 2

Dan Lowe
Dan Lowe

Reputation: 56488

It looks as if you do not have the code program installed. You can open the Command Palette,

  • Mac: ShiftCmdP
  • Windows/Linux: ShiftCtrlP

And search "install command", which should return this as one of the options:

  • Shell Command: Install 'code' command in PATH

Run that, and it should install the code command, after which you should be able to use it.

Upvotes: 48

Related Questions