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

109

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}"
  },
Share:
109
student-f
Author by

student-f

Updated on January 04, 2023

Comments

  • student-f
    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 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.

    • jamesdlin
      jamesdlin about 2 years
      Presumably VS Code sets PATH to something else in its command prompt/PowerShell instances.
  • student-f
    student-f about 2 years
    I added "terminal.integrated.env.windows": {"PATH": "C:\\Program Files\\Java\\jre1.8.0_321\\bin"} to User/settings.json, and I was able to run java from the terminal. But I didn't know how to add multiple directories for the other programs. In the end, I just cleared User/settings.json and I was able to run java and flutter from the terminal.
  • Steven-MSFT
    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.