- Set PATH and other environment variables in Windows 10
- Set environment variables from command prompt
- Set environment variable by Registry edit
- Windows CMD: PATH Variable – Add To PATH – Echo PATH
- Echo Windows PATH Variable
- Add To Windows PATH
- Set Windows PATH For The Current Session
- Set Windows PATH Permanently
- Set path from command line
- How to set path from command line?
- Add directory to system path environment variable:
- Default option is not allowed more than ‘2’ time(s)
- How To Set Path Environment Variables In Windows 10
- Path Environment Variables
- Using Path Environment Variable
- Leave a Reply Cancel reply
- 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
Set PATH and other environment variables in Windows 10
In older windows systems you had to navigate to Advanced System Settings in Control Panel to view, edit or add environmental variables.
- Windows XP — Right-click My Computer, and then click Properties → Advanced → Environment variables → Choose New, Edit or Delete.
- Windows 7 — Click on Start → Computer → Properties → Advanced System Settings → Environment variables → Choose New, Edit or Delete.
In Windows 8 and 10, you can navigate to Advanced System Settings in a similar way.
- Windows 8 — Right click on bottom left corner to get Power User Task Menu → Select System → Advanced System Settings → Environment variables → Choose New, Edit or Delete.
- Windows 10 — Right click on Start Menu to get Power User Task Menu → Select System → Advanced System Settings → Environment variables → Choose New, Edit or Delete.
However, in Windows 10 you can directly get to the Environment Variables window using Search the web and Windows box next to the Start menu. Type environment variables in Windows Search box which gives you two options in search results:
- Edit the system environment variables
- Edit environment variables for your account.
Choose either option and you can add, edit or delete environment variables like PATH.
Set environment variables from command prompt
You can set environment variables from Windows Command Prompt using the set or setx command. The set command only sets the environment variable for the current session. The setx command sets it permanently, but not for the current session. If you want to set it for current as well as future sessions, use both setx and set.
For example, you can set the PATH environment variable permanently (current and future sessions) as below:
To view the current path, run:
- By default setx sets the variable in the local environment (Under HKEY_Current_User Registry key). If you want to set the system variable (Under HKEY_LOCAL_MACHINE registry key), use the flag /m. Start the command prompt as administrator on Windows 10, right click on Start menu and select Command Prompt(Admin).
- The maximum value allowed for a enviroment variable is 1024 characters. So if your variable is long and you try to append to it with setx, you may get a truncated result.
Set environment variable by Registry edit
If your PATH variable is too long, then the best method would be to edit the registry.
For user environment variables, change the key HKEY_CURRENT_USER\Environment . For System Environment variables change
Add, Edit or Delete the environment variable you want to change, then reboot to activate the changes.
Windows CMD: PATH Variable – Add To PATH – Echo PATH
PATH is an environment variable that specifies a set of directories, separated with semicolons ( ; ), where executable programs are located.
In this note i am showing how to print the contents of Windows PATH environment variable from the Windows command prompt.
I am also showing how to add a directory to Windows PATH permanently or for the current session only.
Cool Tip: List environment variables in Windows! Read More →
Echo Windows PATH Variable
Print the contents of the Windows PATH variable from cmd :
The above commands return all directories in Windows PATH environment variable on a single line separated with semicolons ( ; ) that is not very readable.
To print each entry of Windows PATH variable on a new line, execute:
Cool Tip: Set environment variables in Windows! Read More →
Add To Windows PATH
Warning! This solution may be destructive as Windows truncates PATH to 1024 characters. Make a backup of PATH before any modifications.
Save the contents of the Windows PATH environment variable to C:\path-backup.txt file:
Set Windows PATH For The Current Session
Set Windows PATH variable for the current session:
Set Windows PATH Permanently
Run as Administrator: The setx command is only available starting from Windows 7 and requires elevated command prompt.
Permanently add a directory to the user PATH variable:
Permanently add a directory to the system PATH variable (for all users):
Info: To see the changes after running setx – open a new command prompt.
Set path from command line
Users can run an executable from windows command prompt either by giving the absolute path of the file or just by the executable file name. In the latter case, Windows searches for the executable in a list of folders which is configured in environment variables. These environment variables are as below.
1. System path
2. User path
The values of these variables can be checked in system properties( Run sysdm.cpl from Run or computer properties). Initially user specific path environment variable will be empty. Users can add paths of the directories having executables to this variable. Administrators can modify the system path environment variable also.
How to set path from command line?
In Vista, Windows 7 and Windows 8 we can set path from command line using ‘setx’ command.
For example, to add c:\dir1\dir2 to the path variable, we can run the below command.
Alternative way is to use Windows resource kit tools ‘pathman.exe‘. Using this command we can even remove a directory from path variable. See download windows resource kit tools. This works for Windows 7 also.
Add directory to system path environment variable:
Open administrator command prompt
Run the below command
Remove path from system path environment variable:
Run the below command from elevated command prompt
Setting user path environment variable
For user environment varlables, admin privileges are not required. We can run the below command to add a directory to user path environment variable.
To remove a directory from user path, you can run the below command.
Default option is not allowed more than ‘2’ time(s)
You get this error if you have not enclosed ‘path’ in double quotes. See the below example for setting the path of firefox.
Now if you move %path% to be in the double quotes
Could a context entry be created for folders, perhaps an extended one… to add to path?
what about a multi-verb option, like copy as path?
hi, when i use setx at an administrator command line, it creates a USER variable, NOT the SYSTEM variable. What am i doing wrong? How do i change the SYSTEM path at command prompt? -thx
Johny Why
Answer: Try add the parameter /M
Hi, is there a way I can add an extra variable instead on deleting the currently one and put a new Variable on the Path.
I used the command setx /M “c:\Options”, and what it does is delete the current one and then puts that one there, all I want is to add the new variable to the current one. -thx
Nuno, pathman described above does exactly that. You can download the resource tools kit and get it.
setx path “%path%;C:\yourFolder”
To set path for java & javac, can I add the paths to PATH or do I need to create the environment variable JAVA_HOME. I don’t have this defined, but windows does not seem to be able to find java binaries on my system.
You can directly add the folder to PATH. No need to define JAVA_HOME. However, adding JAVA_HOME separately avoids cluttering and helps to easily understand what is added.
hello, can someone plz explain this result? After setting path, it did not change. This was run from an Administrator command-line:
C:\Windows\system32>setx path “C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin”
SUCCESS: Specified value was saved.
C:\Windows\system32>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin;D:\Program Files (x86)\metapad36;D:\Program Files (x86)\metapad36″ /M
Why won’t this work?
SET EPO = D:\Program Files (x86)\McAfee\ePolicy Orchestrator
PATH = %PATH%;%EPO%\jre\bin;%EPO%\apache2\bin
In windows 10 set path %path%; not working. it’s work like :
setx “%path%;C:\Program Files\CodeBlocks\MinGW\bin”
By unfortunately I deleted my system default path. How could I able to find my system path?
Unfortunately I deleted several files with unremembered path names. This article was useful
The following used to work for me when I am in MSDOS environment. Lately I get error messages such as INCLUDE not found. Why is this so?
Used to work
SET PLL =c:\CL5\PLL
SET PLT =c:\CL5\PLL
SET INCLUDE =c:\CL5\INCLUDE
SET PRG =c:\IMS\PRG
SET LIB =c:\CL5\LIB
SET OBJ =c:\CL5\OBJ
PATH =c:\IMS\EXE;\CL5\BIN;\CL5\NG;\CL5\PLL
pathman is one of many tools of the Windows Server 2003 Resource Kit Tools
Note: The Windows Server 2003 Resource Kit Tools are not supported on 64-bit platforms.
Huh.
When I did that on Windows 10 v1903, using setx, it replaced the USER scope paths with the SYSTEM scope paths.
Now I’m not sure what was in the old user path.
So, uh… Be careful out there.
And if anyone has a solution how to avoid that, please let me know
Thanks
How To Set Path Environment Variables In Windows 10
Apr 2, 2018
Comment
Windows has something called ‘Environment Variables’. These are essentially paths and values that point the OS to important locations when there is a need to save files or access essential information about the system. A subset of Environment Variables is the Path variable which points the system to EXE files. Adding a path to an EXE file allows users to access it from anywhere without having to switch to the actual directory. Here’s how to set Path Environment Variables in Windows 10.
You can add any path that you like and there are no restrictions to which drive or folder the EXE should be in. You will need administrative rights to add a Path variable.
Path Environment Variables
Open Control Panel and go to System and Security>System. Alternatively, just type the following in the address bar in File Explorer.
This will take you to the following screen. Click Advanced System Settings.
On the System Properties screen, go to the Advanced tab. Click the Environment Variables button at the very bottom. On the Environment Variables window, select Path from the User variables section and click Edit.
On the Edit Environment variable window, click the New button. This will add a new field inside the list of paths. Once it’s active, click the Browse button and navigate to the folder where the EXE that you want to add to Path environment variables is. Click Ok, and you’re done.
Using Path Environment Variable
When you add an EXE path as an environment variable, you can access the program from any command line. The command line in Windows being the Command Prompt, you can open a Command Prompt in any location and run commands. Which paths you add is entirely up to you since you know which programs you need to access from the Command Prompt. You might, for example, want to add ADB tools as a path variable.
In this brief guide, we’ve talked about adding the path to an EXE however, you can add the path to other executable file types as well. For example, Windows supports running .com, .exe, .bat, and .cmd files from the command line. While this adds considerable convenience, remember that it’s to make using the Command Prompt easier. You can add any path you want to it but keep it clean and add only what’s necessary. Too many paths aren’t going to slow you system down nor are they going to interfere with how you run commands but for long term sanity, keep it concise and if you stop using a particular program, remove its path from environment variables.
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
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.