I have found out that setting the PATH environment variable affects only the old command prompt. PowerShell seems to have different environment settings. How do I change the environment variables for PowerShell (v1)?
Note:
I want to make my changes permanent, so I don't have to set it every time I run PowerShell. Does PowerShell have a profile file? Something like Bash profile on Unix?
You can also modify user/system environment variables permanently (i.e. will be persistent across shell restarts) with the following:
Like JeanT's answer, I wanted an abstraction around adding to the path. Unlike JeanT's answer I needed it to run without user interaction. Other behavior I was looking for:
$env:Path
so the change takes effect in the current sessionIn case it's useful, here it is:
Check out my gist for the corresponding
Remove-EnvPath
function.Building on @Michael Kropat's answer I added a parameter to prepend the new path to the existing
PATH
variable and a check to avoid the addition of a non-existing path:All the answers suggesting a permanent change have the same problem: They break the path registry value.
SetEnvironmentVariable
turns theREG_EXPAND_SZ
value%SystemRoot%\system32
into aREG_SZ
value ofC:\Windows\system32
.Any other variables in the path are lost as well. Adding new ones using
%myNewPath%
won't work any more.Here's a script
Set-PathVariable.ps1
that I use to address this problem:I explain the problem in more detail in a blog post.
Although the current accepted answer works in the sense that the path variable gets permanently updated from the context of PowerShell, it doesn't actually update the environment variable stored in the Windows registry.
To achieve that, you can obviously use PowerShell as well:
More information is in blog post Use PowerShell to Modify Your Environmental Path
If you use PowerShell community extensions, the proper command to add a path to the environment variable path is:
MY SUGGESTION IS THIS ONE i HAVE TESTED THIS TO ADD C:\oracle\x64\bin to Path permanently and this works fine.
The first way is simply to do:
But this change isn’t permenantly, $env:path will default back to what it was before as soon as you close your powershell terminal and reopen it again. That’s because you have applied the change at the session level and not at the source level (which is the registry level). To view the global value of $env:path, do:
or, more specifically:
Now to change this, first we capture the original path that needs to be modified:
Now we define what the new path should look like, in this case we are appending a new folder:
Note: Be sure that the $newpath looks how you want it to look, if not then you could damage your OS.
Now apply the new value:
Now do one final check that it looks how you expect it:
You can now restart your powershell terminal (or even reboot machine) and see that it doesn’t rollback to it’s old value again. Note the ordering of the paths may change so that it’s in alphabetical order, so make sure you check the whole line, to make it easier, you can split the output into rows by using the semi-colon as a delimeter: