'VScode terminal's PATH enviroment variable different from cmd

When i run echo %Path% in vscode's terminal, the result is:

C:\Users\user\.platformio\penv\Scripts;C:\Users\user\.platformio\penv;C:\Users\user\.platformio\python3;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\NAT Service;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files....

But when I run it in the command line(cmd.exe) the result is:

C:\Program Files\AdoptOpenJDK\jdk-8.0.292.10-hotspot\bin;C:\Program Files\AdoptOpenJDK\jdk-16.0.1.9-hotspot\bin;C:\Program Files (x86)\NAT Service;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerSh...

which is different from the one i got in vscode. i tried switching inherit env on and off, restarting vscode, and restarting my computer but nothing changes.

How can i make the %Path% in vscode the same as the one in cmd.exe?

my current vscode settings are:

{
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.external.windowsExec": "C:\\Windows\\System32\\cmd.exe",
"window.zoomLevel": 0,
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"java.configuration.checkProjectSettingsExclusions": false,
"java.errors.incompleteClasspath.severity": "ignore",
"java.project.importOnFirstTimeStartup": "automatic",
"terminal.integrated.tabs.enabled": true,
"files.autoSave": "afterDelay",
"workbench.colorTheme": "Default Dark+",
"java.configuration.runtimes": [
    {
        "name": "JavaSE-16",
        "path": "C:\\Program Files\\AdoptOpenJDK\\jdk-16.0.1.9-hotspot",
        "default": true
    },
    {
        "name": "JavaSE-1.8",
        "path": "C:\\Program Files\\AdoptOpenJDK\\jdk-8.0.292.10-hotspot"
    },
],
"java.home": "C:\\Program Files\\AdoptOpenJDK\\jdk-16.0.1.9-hotspot",
}

for user settings and

"settings": {
    "java.configuration.updateBuildConfiguration": "automatic",
}

for workspace settings



Solution 1:[1]

I reinstalled the PlatformIO extension and this fixed it. Something must have gone wrong with the custom path variable option that comes with PlatformIO

Solution 2:[2]

close last terminal in vs code by trash icon and open new terminal from Terminal>New Terminal menu in vs code in new terminal you can see change's

Solution 3:[3]

If anyone else in the future ends up scratching their heads over this particular problem, I’ve found a culprit:

Showcase of setting Terminal>Integrated>Env: Enable Persistent Sessions

I suspect what happens is that after you update system paths, VScode caches the old path in the terminal and persists it. This is also true even if you restart the browser.

Toggling this option off and restarting VSCode clears that cache, and works perfectly for me. You can toggle it back on after you’re done.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 programmer3481
Solution 2 JJorian
Solution 3