On UNIX, I can edit .bash_profile to extend the PATH variable. On Windows, I know how to edit the PATH via the GUI, but that's annoying if you're interested in automation. What I like about the UNIX approach is that it's easy to save my dotfiles and just install everything automatically with a script that copies / edits files. This is especially useful for me when I'm switching to new computers where I have to set up everything from scratch. Is there an equivalent in Windows? Anything that can be run from a shell works, I need automation, so GUIs won't work.
Add a comment
|
1 Answer
You can do
SET PATH=%PATH%; c:\Directory-to-add
To make a permanent PATH change
SETX PATH "%PATH%;C:\Directory"
By itself, Windows doesn’t have anything like .bash_profile, but there are a number of things you can do to get something similar.
So as not to write too long, I recommend just one:
Get a portable version of Cmder going. Out of the box it comes with everything you need to set up multiple powerful dev environments easily.
It’s built on a Terminal emulator called ConEmu along with many useful development tools.
2 Comments
Eryk Sun
Never use setx.exe to directly modify
PATH. This is a computed variable that's the concatenation of the system and user values, so using setx.exe "%PATH%;..." is making a mess by storing the entire expanded and concatenated PATH value to the user value, which will be concatenated back with the system value when loaded. Every time you do this, you're making a bigger mess.Eryk Sun
Instead you can create another variable named
UserPath that can be modified via setx.exe. Append ;%UserPath% to the user PATH value in the GUI environment editor. The UserPath value should not use % variables because this is the only way to ensure it's loaded before PATH.