The most efficient way to do most things in Windows is through the graphical interface. However, every now and then you need to use the command line to troubleshoot, program or just work on your nerdy cred.
But if you’re trying to run something that isn’t native to Windows, you’ll need to add that to your PATH variable. This tells the system where to look for the executables when you ask for them.
In this article, Niketrainers.com.co will tell you:
What is PATH?
Environment variables store data about the system environment so that the system knows where to look for specific information. The PATH variable is one of the more famous environment variables as it exists on Windows, Mac, and Linux computers and performs a fairly user-oriented task on them. Its real form is just a text string containing a list of directory paths that the system will look for each time you request a program.
It’s a bit like adding a desktop shortcut to the command line. Instead of typing “C: Users username AppData Local Programs Python Python38-32 python.exe” to run Python, you can add the folder containing the file to the PATH variable and just type “python” to run in the future. Do this for any program, whether it is running a GUI (like Notepad) or running in a command line interface (like Python).
In Windows, the PATH (by convention is capitalized because Windows NTFS is not case sensitive) defaults to the “C: Windows” and “C: Windows system32” directories.
If you typecharmap
on the command line you will get a huge list of Unicode characters that you can copy and use, for example. “Notepad” starts Notepad, “msinfo32” lists the computer’s specs, and so on.
These programs can also be launched from the GUI. But if you’re already working on the command line, running programs just by typing their names is much easier. This is especially true if you are trying to run a program that will open and run in a command line interface, such as Python or Node.js.
How do I edit a PATH variable?
The Windows graphical interface is pretty basic, so it’s probably the best way to edit PATH for most people.
Using the Windows GUI
1. Open “System Properties” and go to the “Advanced” tab. The easiest way to do this is by typingenvironment variable
in the Windows search bar and clicking “Edit system environment variables”.
Or you can go to “Control Panel -> System and Security -> System” and click “Advanced system settings”; writessysdm.cpl
in the Run command; or right-click “This PC”, select “Properties” and click “Advanced System Settings”. They all go to the same place.
2. After switching to the “Advanced” tab, click “Environment variables …”
3. There are user variables in the top field, which means that the modifications will only apply to your account. If you have multiple accounts on your computer and you want the changes to affect all of them, edit the bottom field that contains system variables.
4. Select the user or system path variable (don’t be fooled; path and path are the same on Windows) that you want to edit and click “Edit …” below the image.
5. If you already have the path to the folder you want to add, just click “New” and paste the full path (not directly into the executable, but into the folder that contains it). I am pasting the path to my NodeJS directory so that I can use JavaScript on the command line.
6. If you prefer to browse the folder and select it manually, use the “Browse” button to navigate to the folder where the executable is located and hit the “OK” button when you are there.
7. If you want your program to start a little faster, you can use the “Up” and “Down” buttons to move the folder closer to the top so that it appears faster in directory searches.
8. Open a new command prompt window and test your program by typing the name of the executable you want to run. It won’t work in the current window because you’re still using the old PATH variable.
Edit PATH variables using the command line
Windows 10’s graphical interface is very handy and should meet most people’s needs, but if you need to use the command line to set PATH and environment variables, you can too.
1. Open a command prompt as administrator, then enter the commandset
.
2. Scroll through the list of routes and then find the variable you want to edit. thisvariable nameis the part before the “=” sign, thevariable valueis the back which will rename the directory it is to point to.
3. With that in mind, to edit your ROUTE, enter the following command:
setx variable name "variable value"
You can use the following code to set the system PATH from the command line. (Execute as administrator). To use it to configure the user path, just delete/M
.
setx / M PATH "% PATH%; <path-to-executable-folder>"
If you are having problems, it is a good idea to see the known issues and fixes for thesetx
command truncates the variable to 1024 characters or otherwise changes the variables. Definitely back up user path and system variables first.
Frequent questions
1. Why should I edit my PATH?
Chances are, if you’re reading this, you’ve come across something that requires you to add this to your PATH variable, so you should probably do that. However, if you just want to add something to your PATH for easier access, that’s fine too. Just make sure it doesn’t interfere with higher priority programs.
2. Is there a Windows PATH length limit?
Yes, they are. Therefore, PATH enthusiasts should remember that the limit is 260 characters.
3. Can I turn off the Windows PATH length limit?
If you can! Go to Registry Editor and then go to:
HKEY_LOCAL_MACHINE SYSTEMCurrentControlSetControlFileSystem
In the right pane, double-click on the entry named “LongPathsEnabled” and then change the value “Value data” from 0 to 1. Click OK and you are done.
Ready to mine under the hood of Windows? Then head over to our favorite Windows registry tricks. Or if you’re looking for something a little lighter, check out our list of the best Windows 10 themes.