6

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.