- 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
- How to Add to Windows PATH Environment Variable
- Add Directories to PATH Variable
- Windows 7 — Add Path
- 6 Answers 6
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.
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
Windows 7 — Add Path
I need to add a new path (sumatraPDF) on my PATH variable .
I don’t know why it does not work.
I think everything is right but when I try to execute sumatrapdf.exe from CMD it cannot find the program.
This is what I did:
The path is correct, I checked it 1000 times.
The idea is use LaTeX with sublimetext and when I save a .text file sumatra has to open and show to me the result. If I want that I have to add the path of SumatraPDF. but it does not work.
6 Answers 6
I think you are editing something in the windows registry but that has no effect on the path.
the variable of interest is the PATH
also you can type on the command line:
Another method that worked for me on Windows 7 that did not require administrative privileges:
Click on the Start menu, search for «environment,» click «Edit environment variables for your account.»
In the window that opens, select «PATH» under «User variables for username» and click the «Edit. » button. Add your new path to the end of the existing Path, separated by a semi-colon ( %PATH%;C:\Python27;. ;C:\NewPath ). Click OK on all the windows, open a new CMD window, and test the new variable.
I founded the problem: Just insert the folder without the executable file.
so Instead of:
you have to write this:
In answer to the OP:
The PATH environment variable specifies which folders Windows will search in, in order to find such files as executable programs or DLLs. To make your Windows installation find your program, you specify the folder that the program resides in, NOT the program file itself!
So, if you want Windows to look for executables (or other desired files) in the folder:
because, for example, you want to install PHP manually, and choose that folder into which to install PHP, then you add the entry:
to your PATH environment variable, NOT an entry such as «C:\PHP\php.exe».
Once you’ve added the folder entry to your PATH environment variable, Windows will search that folder, and will execute ANY named executable file you specify, if that file happens to reside in that folder, just the same as with all the other existing PATH entries.
Before editing your PATH variable, though, protect yourself against foul ups in advance. Copy the existing value of the PATH variable to a Notepad file, and save it as a backup. If you make a mistake editing PATH, you can simply revert to the previous version with ease if you take this step.
Once you’ve done that, append your desired path entries to the text (again, I suggest you do this in Notepad so you can see what you’re doing — the Windows 7 text box is a pain to read if you have even slight vision impairment), then paste that text into the Windows text box, and click OK.
Your PATH environment variable is a text string, consisting of a list of folder paths, each entry separated by semicolons. An example has already been given by someone else above, such as:
Your exact version may vary depending upon your system.
So, to add «C:\PHP» to the above, you change it to read as follows:
Then you copy & paste that text into the windows dialogue box, click OK, and you should now have a new PATH variable, ready to roll. If your changes don’t take effect immediately, you can always restart the computer.