Environment Variables On Windows 10 - Complete Guide
![]() (Jan. 2020) Gone are the days when we had to know how to set up a variety of advanced parameters on the OS for a computer to work correctly. Nowadays, modern OSes usually take care of that, but on some rare occasions, we do need to get our hands dirty and do it ourselves. Shortcuts: How to set them from command line How to set them from Powershell What are Environment Variables and when do you need to set themAn environment variable is a dynamic-named value that can affect the way running apps behave on a computer. An app may need to know the location of a package (or other data) of another app to run accurately. Therefore they use a predefined environment variable to share this location. We'll get into some examples right away. How to set an environment variable on windows.The quickest way to get there is to press WIN+PAUSE or WIN+BREAK and then on Advanced system settings, click on Environment Variables.
You can also press the WIN key, type , and then under the Best match heading, click on View advanced system settings.
Or you can press WIN+R and type .
You'll have two types of Environment Variables (EVs), user variables and system variables. The former is a list of values (usually folder names) assigned to your data, while the latter is related to your machine. You then click on New and add a variable name and a Variable value.
Let's try now with a typical example. How to set Java environment variables on Windows 10 (Java classpath)Java is a multi-platform programming language and runtime that needs to be available to Java-based apps. With the help of an EV, they know precisely where the runtime executable is. That's something I still have to do now and then on some machines.
How to set an environment variable from the command lineIf you prefer a "copy and paste" solution, there's also an easy way using the Windows command line. Just follow the next set of instructions carefully.
We'll get to an example shortly.
For this process to take effect, you have to logout and log back in again. How to add Java to the path variable on Windows 10 (Java classpath)Lets set an EV from the command line again, with a Java example. path is one of the most popular variable names on Windows. It defines the location of every app's executable. Whenever the user (or another app) tries to run that app, it can do so, even without knowing where it is located on this particular machine. You can use the command line to set its value. Warning!This is only for the sake of this example. DO NOT try this with the path variable, or you can mess up your computer.
Creating a new EV makes it easier to manage the value of the path EV in the future. Whenever you need to upgrade (change) the JDK version, all you need to do is set that new EV value again. Adding a new folder to path is safer because it doesn't set a new value. Instead, it adds a new variable value. The % enclosure represents the variable value instead of the variable name. The ; is a folder delimiter. Be aware that C:\Program Files\Java\jdk1.8.0 may not be the Java installation folder on your machine. To confirm that everything is in order, exit the command line, open it again, and then type If you found a mistake, remember that How to set an environment variable on PowershellIf Powershell is your thing, then you can also easily set an EV (or add a new variable value) on it.
This isn't permanent. As soon as you close Powershell, the EV will default back to what it was before. If you need a permanent solution, check out the following example. How to add Python to the path variable on Windows 10 using PowershellLet's use this popular programming language as an example by adding its executable to the path EV. After opening Powershell, with administrative privileges, you can type (for version 3.2 of this program), but we already saw that this isn't permanent. So, if you want to write any value to the Windows Registry, try this instead:
This will add a new value to the path EV in the machine (system) environment. You'll have to restart Powershell for changes to take effect. In the end, don't forget to do one final check if your EVs have the value that you expected. You can type path variable, make sure you are adding (and not replacing) a value. Otherwise, you could be damaging your OS. I'm still going to give you an example of how to replace a value instead of adding it: path to something else or c:\ to the appropriate value). ConclusionI hope I've covered every possible way of changing, adding, and checking EV values. If, for any reason, something did not work for you or you still have any doubts, leave a comment below or contact me and I'll try to help as much as I can. For more information about EVs, check this Wikipedia link: https://en.wikipedia.org/wiki/Environment_variable#Windows
|
|