Why can't I run commands like 'java' from the Visual Studio Code terminal?

Viewed 229

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 typing java 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 typing java 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 and flutter fine from the regular Windows Command Prompt (their bin folders are in the Path 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" from User/settings.json.

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

Now I can run commands like java, flutter (etc.) from the VS Code terminal.

3 Answers

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}"
  },

I think you are running java using the direct run button do use java "run java" the button on the side and check if it's working.

enter image description here

  1. Install the necessary extensions from the marketplace in VS CODE. (i.e Java and Dart if you have not already.

  2. Search Environment Variables and follow what I have done in the picture. You have to simply add the bin folder link in the env variables like I have added the scripts folder link to enable python commands globally.

  3. For java you might most probably need JRE or something like that if you are looking forward to do App development and you will most probably need Android studio installed as well even if you don't want to use it.

enter image description here

Related