42

I added a directory to my PATH but the terminal in my VS Code doesn't recognize a command(exe) that I'm trying to run from that directory. The terminal uses cmd not power shell. What am I missing?

3
  • 1
    Where did you add a directory to your PATH? System level with SETX? Inside VS Code? Did you restart VS Code after adding it? Commented Jul 2, 2017 at 18:31
  • At a system level. Not inside VS code and I did restart VS code. Commented Jul 3, 2017 at 13:09
  • All people modifying the system or user environment variable Path should take a look on: What is the reason for "X is not recognized as an internal or external command, operable program or batch file"? That long answer explains in full details how the most important environment variable PATH is managed by Windows and used by applications like the Windows Command Processor (cmd.exe) , PowerShell, Windows Script Host (cscript.exe and wscript.exe) and other executables like VS Code and other IDEs. Commented Nov 7 at 6:03

13 Answers 13

42

Restarted my computer and it worked :) Apparently VS Code didn't recognize the changes.

Sign up to request clarification or add additional context in comments.

4 Comments

In my case restarting VSCode didn't help, all built-in terminals didn't see the new PATH value. Singing out and in my Windows account helped.
Alternatively, you can log out and then log back in. VSCode is just dumb at recognizing the change in PATH variables.
I closed all VSCode instances, and then it worked when I re-opened.
closing all vscode instances worked for me as well
28

For me, a simple restart of VSC did the trick.

3 Comments

Note that 'Restart to Update' does not pick up the new PATH when it starts again. Click X to close the app, check that the VS Code process is not present in Task Manager then open VS Code again, either from shortcut or by entering code in a cmd window. Then it picked up the updated PATH.
Also if you have more than one instance of vs code open, you need to close them all before restarting vs code for it to recognize the change
For me, restarting vscode didn't help, however "Remote-SSH: Uninstall VS Code Server from Host..." work for me to this issue.
9

If your VS Code terminal shows "Session Restored" after restarting, then it may still be using the variables from before you rebooted! If this happens, close and re-open the vscode window, or kill and restart the terminal tab.

1 Comment

This was the answer for me. Persisted past a reboot!
6

In my case, I had several VS Code instances opened, so I had to close all the opened instances in order to apply the changes

Comments

3

Clicking the bin/trash icon on the terminal to properly kill it and then CTRL + ' to open a new terminal works best. No need to close the app or shut down your PC.

enter image description here

2 Comments

A screenshot of this "bin icon" might help (not everyone calls the trash button a "bin"). Also, can do this through the command palette: "Terminal: Kill the Active Terminal Instance" and then "Terminal: Create New Terminal".
This didn't work for me. I installed terraform on my windows machine, and killed and launched a new terminal instance in vscode, yet powershell wouldn't recognize it (powershell recognized the name just fine when run outside of vscode). But once I opened a new vscode window and ran terraform, it worked
2

Sometimes this problem can happen when you misuse .bash_profile and .bashrc.

As mentioned in many materials, .bash_profile is executed for interactive login shells, and .bashrc is executed for interactive non-login shells.

VSCode terminal is interactive non-login shells. So, be sure you have correctly define your PATH and other environment variables in .bashrc

Comments

1

Go to settings.json and make sure this environment variable has empty json inside it:

"terminal.integrated.env.windows": { }, 

Comments

1

I had this issue but all of the previous solutions in this question did not work. I found that on Windows 11 doing a custom Python install the PYTHONPATH env variable had not been set. Creating and setting up the PYTHONPATH variable, and then restarting terminals fixed the same issue for me.

1 Comment

The environment variable PYTHONPATH is used only by Python (python.exe and pythonw.exe) to find Python modules (dynamically loaded libraries) imported in Python scripts as it can be read in the Python documentations Command line and environment, Using Python on Windows, Modules. This answer is related therefore only for Python script programmers and not for VS Code users in general.
0

If nothing works and you don't want to restart your computer.

For windows;

  1. Open a command prompt (outside vscode) and type echo %PATH%
  2. Copy the path
  3. Open your terminal in vscode and type PATH=<your-path> (replace <your-path> with the output)

Note: This is a temporary solution and goes away if you close the terminal and open a new one.

Comments

0

Another point of info that might solve the problem for some people. It's not obvious, but if you have multiple instances of VSCode open and you close one of them and relaunch it, it will pick up state from the other instances that are still open. So if you're trying to figure out why VSCode refuses to pick up new environment variables even after you've closed and reopened it, check that you don't have another VSCode process running at the same time as it will "help" the new process get started more quickly, sabotaging your attempt to solve the problem.

Comments

0

When setting environment variables, use ";" instead of ":", in Windows, this is the problem I encountered

Comments

-2

I had some files remaining in the folder 'c:\Program Files\nodejs', deleted the folder and it all worked.

Comments

-2

For me, it turns out that VS Code was not on my Path even though it should have automatically been added after the install. This could be the case if you use the command 'code' and it is not recognized. Adding

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

to my User PATH and restarting the terminal (and VS Code) fixed the issue on my machine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.