Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Powershell Environment PATH different to the System Environment PATH?

I'm having this weird situation :

My user's and system's PATH variable is different than the PATH in powershell.

When I do :

PS C:\$env:path C:\Windows\System32\WindowsPowerShell\v1.0\;c:\oldpath 

However this is not correct, it looks like it stuck on some old PATH variable of my system, so none of the udpates I've done on it didn't change this variable (I do restart after every change to test).

Why is this happening? Do I have to set a PATH variable just for powershell?

like image 531
dr. evil Avatar asked Feb 13 '09 16:02

dr. evil


People also ask

Why is PowerShell path different?

This is usually the interactive shell (explorer.exe). When you modify the environment from computer properties, you modify the environment of explorer.exe, so if you launch powershell from explorer.exe, (for example from the start menu) you should see the new environment.

What is the system environment path?

The PATH environment variable is an important security control. It specifies the directories to be searched to find a command. The default systemwide PATH value is specified in the /etc/profile file, and each user normally has a PATH value in the user's $HOME/. profile file.

What is the difference between path and environment variable?

An environment variable is used by the operating system to find the executable files. An environment variable is used by the Java compiler to find the path of classes. 2. PATH setting up an environment for the operating system.

What is the PowerShell path?

64 bits version: C:\Windows\System32\WindowsPowerShell\v1. 0\


2 Answers

The change might be "delayed", so try one or more of these solutions:

  • Log off and on again;
  • Task Manager > Restart "Windows Explorer" (explorer.exe)
  • Restart your launcher app (launchy, SlickRun, etc)
  • Reboot

Explanation:
Powershell will inherit the environment of the process that launched it (which depends on how you launch it). This is usually the interactive shell (explorer.exe). When you modify the environment from computer properties, you modify the environment of explorer.exe, so if you launch powershell from explorer.exe, (for example from the start menu) you should see the new environment.

However, if you launch it from something else (say a cmd.exe shell that you already had opened), then you won't since that process was launched under the old environment.

In other words: be careful how you are launching things.

like image 132
zdan Avatar answered Oct 05 '22 23:10

zdan


In my case, I installed an app that incorrectly added itself to the PATH by creating a powershell profile that would override $env:PATH and blow out the existing configuration every time I started powershell.

Check if you have profile at USER\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 and if it's doing anything fishy like setting $env:PATH.

like image 25
DannyLongFingers Avatar answered Oct 06 '22 00:10

DannyLongFingers