18

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

moreover 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 .

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Nikhil S
  • 3,786
  • 4
  • 18
  • 32
  • Did you just recently install VS Code? If so, did you restart the Command Prompt after installation? – vcsjones May 04 '18 at 20:19
  • Did you have a terminal open? – Natsfan May 05 '18 at 00:51
  • @vcsjones yes i have recently installed VS code and i have restarted Command prompt after installation – Nikhil S May 05 '18 at 10:52
  • Possible duplicate of [code . is not recognized as an internal or external command](https://stackoverflow.com/questions/46638944/code-is-not-recognized-as-an-internal-or-external-command) – d.moncada May 06 '18 at 02:31

10 Answers10

46

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.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • 2
    FYI - Windows doesn't have a command palette option starting with "Shell Command" ([screenshot](https://i.stack.imgur.com/J2QW9.png)). See my answer below for [how to install code to path **on windows**](https://stackoverflow.com/a/73137747/1366033) – KyleMit Jul 27 '22 at 12:06
21

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"
Malte Schwerhoff
  • 12,684
  • 4
  • 41
  • 71
starryknight
  • 239
  • 2
  • 5
8

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.

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
Nikhil S
  • 3,786
  • 4
  • 18
  • 32
  • Make sure that the Environment variables for this path is in the first place. If not move to the top. This worked for me only after moving this path to first place in the order. – psuneel127 Jul 13 '20 at 15:52
3

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 !

arunlazer
  • 41
  • 5
2

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)

  • This works with WSL in Linux shell. Very helpful thx! Path to 'code-insiders' is maybe \home\\.vscode-server-insiders\bin\. . .\bin ('.' directories/files are hidden by default so you can use `ls -ld .*` to view them. – Gregory Somers Oct 28 '21 at 15:51
2

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

KyleMit
  • 30,350
  • 66
  • 462
  • 664
1

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

Greg Witt
  • 61
  • 5
0

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

Vibha
  • 939
  • 9
  • 17
0

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 .

nativelectronic
  • 646
  • 4
  • 11
0

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\

Kevin Nzioka
  • 785
  • 1
  • 6
  • 11