Why can't I run commands like 'java' from the Visual Studio Code terminal?
Have you configured terminal.integrated.env.xxx
in the settings.json file? Such as this:
"terminal.integrated.env.windows": { "Path": "" }
Please check your configuration files both User
and Workspace
.
Update:
If you want to modify the system environment variables
such as path
, but you still want to retain
the system environment variable
on your computer. You can take ${env:Path}
to get the old value on your computer. Like this:
"terminal.integrated.env.windows": {
"Path": "some new paths;${env:Path}"
},
student-f
Updated on January 04, 2023Comments
-
student-f over 1 year
Question
I'm using Visual Studio Code's terminal (on a Windows 11 device) and can't run commands like
java
,flutter
etc., be it VS Code's Powershell terminal or VS Code's Command Prompt terminal.When I try to run
java
by typingjava
in the VS Code Powershell terminal, it displays:PS C:\users\user> java java : The term 'java' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + java + ~~~~ + CategoryInfo : ObjectNotFound: (java:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
When I try to run
java
by typingjava
in the VS Code Command Prompt terminal, it displays:C:\users\user> java 'java' is not recognized as an internal or external command, operable program or batch file.
I can run
java
andflutter
fine from the regular Windows Command Prompt (theirbin
folders are in thePath
environment variables).How do I allow these commands to be run in the VS Code terminal?
I've tried uninstalling and reinstalling VS Code, thinking I would be able to then run the commands, but I get the same problem.
I'm already able to run a java program using the "Run java" button in the top-right of the window. However, I want to be able to run java by entering the command in the VS Code terminal, similarly to running commands in Command Prompt.
I already have the "Extension Pack for Java extension" and "Dart" extensions for VS Code.
Solution
Thanks to @Steven-MSFT!
My
User/settings.json
contained:"terminal.integrated.env.windows": { "PATH": "C:\\ghcup\\ghc\\8.10.7\\bin" },
I deleted
"PATH": "C:\\ghcup\\ghc\\8.10.7\\bin"
fromUser/settings.json
."terminal.integrated.env.windows": { },
Now I can run commands like
java
,flutter
(etc.) from the VS Code terminal.-
jamesdlin about 2 yearsPresumably VS Code sets
PATH
to something else in its command prompt/PowerShell instances.
-
-
student-f about 2 yearsI added
"terminal.integrated.env.windows": {"PATH": "C:\\Program Files\\Java\\jre1.8.0_321\\bin"}
toUser/settings.json
, and I was able to runjava
from the terminal. But I didn't know how to add multiple directories for the other programs. In the end, I just clearedUser/settings.json
and I was able to runjava
andflutter
from the terminal. -
Steven-MSFT about 2 years@student-f Could you have a look at the update? And if it is helpful, could you accept this answer? then other people can find this answer easier.