- Add to the PATH on Windows 10
- How to Add to Windows PATH Environment Variable
- Add Directories to PATH Variable
- Adding and Editing PATH Environment Variables in Windows
- Adding a Directory to the User Path Variable from the Command Line
- Adding a Directory to the System Path Variable from the Command Line
- Adding a Directory to the Path Variable from the GUI
- Removing Directories from the PATH Variable
- Adding a directory to the PATH environment variable in Windows
- 18 Answers 18
- Option 1
- Option 2
- Safer SETX
- Warnings
- Usage instructions
- Append to User PATH
- Append to System PATH
- Alternatives
Add to the PATH on Windows 10
📅 March 17, 2018 ⏱ 1 min read
Hello fellow internet citizens! Here is a concise guide to modifying the PATH on Windows 10!
- Open the Start Search, type in “env”, and choose “Edit the system environment variables”:
- Click the “Environment Variables…” button.
- Under the “System Variables” section (the lower half), find the row with “Path” in the first column, and click edit.
- The “Edit environment variable” UI will appear. Here, you can click “New” and type in the new path you want to add. From this screen you can also edit or reorder them.
- Dismiss all of the dialogs by choosing “OK”. Your changes are saved!
- You will probably need to restart apps for them to pick up the change. Restarting the machine would ensure all apps are run with the PATH change.
To test it, in new PowerShell window, type:
Written by Ryan Hoffman, an experienced team leader, certified Scrum Master and software architect.
Contact RyanFollow Ryan on Twitter
How to Add to Windows PATH Environment Variable
Works for Windows 10 or 7
If you’re a coder or programmer, you probably spend a decent amount of time using the command prompt to execute programs or compile code. In order to complete those tasks, you most likely have to use a command from a library or software package installed (like Python) on your system.
By default, most of these programs will add their own custom shortcuts to the Windows environment variables. The most used environment variable in Windows is probably the PATH variable. It basically allows you to run any executables that are located inside the paths specified in the variable at the command prompt without having to give the full path to the executable.
In this article, I’ll show you how you can add more paths to the Windows PATH variable in case you want to run executables from your own custom directories. It’s worth noting that the procedure below is for Windows 10, but it’s almost exactly the same for Windows 7 also.
Add Directories to PATH Variable
To get started, right-click on the Computer or This PC icon on the desktop and select Properties. If you don’t have that icon on your desktop already, you can add any missing desktop icons easily.
On the System dialog page, you’ll see an Advanced system settings link on the left-hand side.
This will bring up the System Properties dialog, which should already be open to the Advanced tab. Go ahead and click on the Environment Variables button at the very bottom.
On the Environment Variables dialog, you’ll see two sets of variables: one for user variables and the other for system variables. Both lists have the PATH variable, so you have to decide which one to edit.
If you only need the commands for your own user account, then edit the user variable. If you need it to work across the computer system regardless of which user is logged in, then edit the system variable. Click on Path and then click on Edit.
On the Edit environment variable dialog, you’ll see a list of all the paths that are currently in the PATH variable. As you can see, Node.js and Git already added their paths so that I can run Git commands and Node.js commands from anywhere while in the command prompt.
To add a new path, simply click on New and it’ll add a new line to the bottom of the list. If you know the path, simply type it in or copy and paste it. If you prefer, you can also click Browse and then navigate to the desired path.
To edit any path, simply select it and then click on the Edit button. You can also delete paths using the Delete button. Note that you can also move items up and down on the list. When you type a command at the command prompt, Windows has to search through each directory stored in the PATH variable to see if that executable exists or not. If you want your executable to be found faster, just move that path up to the top of the list.
This can also come in handy if you have multiple versions of the same command in different paths and need to have one run instead of the other. The one that shows up higher in the list will be run when you type in the command.
Lastly, if you click on Edit text, it will load a dialog where you can edit the Path variable using the old interface where all the paths are listed in one text box.
That’s all there is to it! If you want to learn more about environment variables, make sure to check out my post on how to create your own custom environment variables. Enjoy!
Founder of Help Desk Geek and managing editor. He began blogging in 2007 and quit his job in 2010 to blog full-time. He has over 15 years of industry experience in IT and holds several technical certifications. Read Aseem’s Full Bio
Adding and Editing PATH Environment Variables in Windows
Sometimes we need to tell Windows where to look for a particular executable file or script. Windows provides a means to do this through the Path Environment Variable. The Path Environment Variable essentially provides the OS with a list of directories to look in for a particular .exe or file when the simple name of the file is entered at the command prompt.
For example, the Notepad.exe application resides in the C:\Windows\system32 directory. However, if we wish to open the Notepad application via the Windows Command Line, we need only type:
Opening Notepad.exe From the Windows Command Line:
This works because the Path variable on Windows by default contains a list of directories where application files and scripts are likely to be located. Each directory in the list is separated by a semi-colon.
Similarly, there is another environment variable, PATHEXT which specifies a list of file extensions which might be found when searching for the proper file within the paths in the Path variable. This is why we are able to type simply “Notepad” at the command prompt, instead of Notepad.exe.
Windows will first search the current directory (where the command prompt is a the time the command is executed) to find a name matching the one typed into the terminal, and then search the directories in the Path variable in order, beginning with the most likely locations, and continue until either a matching file name is located, or else return the “… is not recognized blah blah” message at the terminal.
Once a file with a matching name is located, Windows attempts to match the file extension (if one is present), again in the order specified in the PATHEXT variable. If a match is found, the file is processed accordingly.
There are both User-specific and machine-level PATH variables. Machine Path variables are available globally across the machine, and can only be modified by administrators. User Environment variables can be modified by both administrators, and the user with which the current profile is associated.
Adding a Directory to the User Path Variable from the Command Line
Any user can modify their own PATH variable from the Command Line (unless they have been specifically denied this ability by an administrator).
For example, when we wish to use SQLite from the Windows Command Line, we download the SQLite binaries, and place them in the directory of choice. However, in order to use the SQLite Command Line application without either navigating directly to the folder in which we placed it, or entering the full file path into our Windows Command Line, we need to add the directory containing the SQLite.exe to our User or System PATH environment variable.
Let’s say a user has downloaded the sqlite3.dll and sqlite3.exe binaries and located them in the directory C:\SQLite.
Now, in order to invoke the sqlite3.exe from the command line, we need to add the C:\SQLite directory to our PATH environment variable. We can do this from the command line by using the setx command:
The setx Command – Syntax:
When we modify environment variables using setx , the changes are not available in the current Console session – in other words, in order to see our changes, we need to exit, and open a new Console window. Then, we can use the following technique:
We can examine the contents of the PATH variable by typing:
Output PATH Variable to the Console:
Which gives the output:
Results of Echo %PATH% Command:
We can see here that C:\SQLite has now been added to the paths available to the current user.
Adding a Directory to the System Path Variable from the Command Line
In the previous section, we used the setx command to add a directory to the current user’s Path variable. Sometimes, we want to make variables available at the system, or machine level. In that case, we use the same setx command in conjunction with the /m flag. However, we need to run the Command Terminal as Administrator for this to work:
Add a Directory the the System PATH Variable Using the /m Flag:
Adding a Directory to the Path Variable from the GUI
Or, we can do this using the GUI by navigating to Control Panel => All Control Panel Items => System, and then selecting the “Advanced System Settings” link:
Locate Advanced System Settings in Control Panels:
Then locate the “Environment Variables” button:
Open Environment Variables:
Opening Environment Variables, we see the following:
Editing Environment Variables:
Notice in the image above, there are two sections, User Variables for , and System Variables.
Also note, there is not currently a Path variable for me, the current user. We will need to add one, and then add our new path to it:
Adding a User Path Variable in the Windows GUI:
Once we hit OK, We see we have the single item added to our user path variable.
Added Path Variable to User Environment Variables:
For some reason, this works differently than when we do this from the Command Line, when we use the setx command from the terminal, the entirety of the system path variable is copied into the user path variable, including the new entry.
If we have Administrator permissions on our machine, we can do the same for the System PATH variable if we so choose.
Removing Directories from the PATH Variable
In some cases, we may need to remove a directory from our PATH variable. In these cases it is recommended to use the GUI, or edit the registry. It’s easiest to simply open the GUI, copy the contents of the PATH variable (either the User Path or the System Path) to a text editor, and remove the entries you want to delete. Then paste the remaining text back into the Edit Path window, and save.
Adding a directory to the PATH environment variable in Windows
I am trying to add C:\xampp\php to my system PATH environment variable in Windows.
I have already added it using the Environment Variables dialog box.
But when I type into my console:
it doesn’t show the new C:\xampp\php directory:
I have two questions:
- Why did this happen? Is there something I did wrong?
- Also, how do I add directories to my PATH variable using the console (and programmatically, with a batch file)?
18 Answers 18
This only modifies the registry. An existing process won’t use these values. A new process will do so if it is started after this change and doesn’t inherit the old environment from its parent.
You didn’t specify how you started the console session. The best way to ensure this is to exit the command shell and run it again. It should then inherit the updated PATH environment variable.
Option 1
After you change PATH with the GUI, close and re-open the console window.
This works because only programs started after the change will see the new PATH .
Option 2
Execute this command in the command window you have open:
This command appends C:\your\path\here\ to the current PATH .
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 .
WARNING: This solution may be destructive to your PATH, and the stability of your system. As a side effect, it will merge your user and system PATH, and truncate PATH to 1024 characters. The effect of this command is irreversible. Make a backup of PATH first. See the comments for more information.
Don’t blindly copy-and-paste this. Use with caution.
You can permanently add a path to PATH with the setx command:
Remove the /M flag if you want to set the user PATH instead of the system PATH .
- The setx command is only available in Windows 7 and later.
You should run this command from an elevated command prompt.
If you only want to change it for the current session, use set.
You don’t need any set or setx command. Simply open the terminal and type:
This shows the current value of PATH variable. Now you want to add directory to it? Simply type:
If for any reason you want to clear the PATH variable (no paths at all or delete all paths in it), type:
Update
Like Danial Wilson noted in comment below, it sets the path only in the current session. To set the path permanently, use setx but be aware, although that sets the path permanently, but not in the current session, so you have to start a new command line to see the changes. More information is here.
To check if an environmental variable exist or see its value, use the ECHO command:
I would use PowerShell instead!
To add a directory to PATH using PowerShell, do the following:
To set the variable for all users, machine-wide, the last line should be like:
In a PowerShell script, you might want to check for the presence of your C:\xampp\php before adding to PATH (in case it has been previously added). You can wrap it in an if conditional.
So putting it all together:
Better still, one could create a generic function. Just supply the directory you wish to add:
You could make things better by doing some polishing. For example, using Test-Path to confirm that your directory actually exists.
Safer SETX
- SETX by default will update your user path.
- SETX . /M will update your system path.
- %PATH% contains the system path with the user path appended
Warnings
- Backup your PATH — SETX will truncate your junk longer than 1024 characters
- Don’t call SETX %PATH%;xxx — adds the system path into the user path
- Don’t call SETX %PATH%;xxx /M — adds the user path into the system path
- Excessive batch file use can cause blindness 1
The ss64 SETX page has some very good examples. Importantly it points to where the registry keys are for SETX vs SETX /M
Usage instructions
Append to User PATH
Append to System PATH
append_system_path.cmd . Must be run as administrator.
(It’s basically the same except with a different Key and the SETX /M modifier.)
Alternatives
Finally there’s potentially an improved version called SETENV recommended by the ss64 SETX page that splits out setting the user or system environment variables.
1. Not strictly true
Handy if you are already in the directory you want to add to PATH:
It works with the standard Windows cmd, but not in PowerShell.
For PowerShell, the %CD% equivalent is [System.Environment]::CurrentDirectory .
- Command line changes will not be permanent and will be lost when the console closes.
- The path works like first comes first served.
- You may want to override other already included executables. For instance, if you already have another version on your path and you want to add different version without making a permanent change on path, you should put the directory at the beginning of the command.
To override already included executables;
Aside from all the answers, if you want a nice GUI tool to edit your Windows environment variables you can use Rapid Environment Editor.
Try it! It’s safe to use and is awesome!
It does things in an intuitive way. For example:
It shows results without the need to spawn a new cmd!
Regarding point 2 I’m using a simple batch file that is populating PATH or other environment variables for me. Therefore, there is no pollution of environment variables by default. This batch file is accessible from everywhere so I can type:
Checking the above suggestions on Windows 10 LTSB, and with a glimpse on the «help» outlines (that can be viewed when typing ‘command /?’ on the cmd), brought me to the conclusion that the PATH command changes the system environment variable Path values only for the current session, but after reboot all the values reset to their default- just as they were prior to using the PATH command.
On the other hand using the SETX command with administrative privileges is way more powerful. It changes those values for good (or at least until the next time this command is used or until next time those values are manually GUI manipulated. ).
The best SETX syntax usage that worked for me:
where any equal sign ‘=’ should be avoided, and don’t you worry about spaces! There isn’t any need to insert any more quotation marks for a path that contains spaces inside it — the split sign ‘;’ does the job.
The PATH keyword that follows the SETX defines which set of values should be changed among the System Environment Variables possible values, and the %PATH% (the word PATH surrounded by the percent sign) inside the quotation marks, tells the OS to leave the existing PATH values as they are and add the following path (the one that follows the split sign ‘;’) to the existing values.