Adding a directory to the PATH environment variable in Windows
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
To add a directory to the PATH environment variable in Windows, you can follow these steps:
- Open the Start menu and search for “Environment Variables” or “Edit the system environment variables.” Select the option that allows you to edit the system environment variables.
- In the System Properties window, click on the “Environment Variables” button.
- In the Environment Variables window, you’ll see two sections: User variables and System variables. The User variables section contains variables specific to your user account, while the System variables section contains variables accessible by all users on the system. To add a directory for all users, choose a variable from the System variables section (e.g., Path).
- Select the variable (Path) and click the “Edit” button.
- In the Edit Environment Variable window, click on the “New” button.
- Enter the directory path you want to add (e.g., C:\YourDirectory) and click “OK.”
- Click “OK” in the Environment Variables window to save the changes.
- Close any open command prompt windows and reopen them to ensure the new PATH variable takes effect. Alternatively, you can restart your computer.
Option 1
After you change PATH with the GUI, close and reopen the console window.
This works because only programs started after the change will see the new PATH.
Option 2
This option only affects your current shell session, not the whole system. Execute this command in the command window you have open:
This command appends C:\your\path\here\ to the current PATH. If your path includes spaces, you do not need to include quote marks.
Breaking it down:
set – A command that changes cmd’s environment variables only for the current cmd session; other programs and the system are unaffected.
PATH= – Signifies that PATH is the environment variable to be temporarily changed.
%PATH%;C:\your\path\here\ – The %PATH% part expands to the current value of PATH, and ;C:\your\path\here\ is then concatenated to it. This becomes the new PATH.