Jar Bar & Windows PATH Environment Variable by Yucca Nel
The PATH variable is a heavily used variable in programming. We use it to pinpoint the location of core libraries and kits to be used when developing. Because the PATH is nothing more than an environment or System variable, this tutorial can be used for all other environment variables such as "JAVA_HOME", "M2_HOME", "CATALINA_HOME", etc. The common difference is that we typically add "bin" directories to our "PATH" and typically, use other environment variables to define locations of other files needed by programs. This allows for pre written servers/applications to request the location of these files by looking for the environment variable. This allows users to customize the location of where they wish to have their Maven, Tomcat, etc. installed and then provide the program with these locations systematically.
Other Environment Variables
This guide can therefore be used for not just the PATH environment variable, but all other related variables such as M2_HOME, JAVA_HOME, etc. Usually these variables point to the home directory of the install and not the "bin".
The PATH is heavily used
Because the PATH is heavily used, it usually contains many entries separated with a semicolon (;).
Setting the PATH permanently
Choosing how we set the variables affects the period of time that the variable is available for usage. If we set the variable in the Command Prompt in Windows or the shell/terminal in Unix based systems, then it may only kept available for use for as long as the terminal/shell/CLI are kept open (commonly called a session). In most cases though, we define it in a place where the variable is accessed and available at anytime AFTER we have done a System restart. This guide uses this method.
How the PATH is read (Multiple Matches)
When dealing with the PATH environment variable, the system looks for the first match and then executes the first winning entry. This is useful when defining multiple locations for backward compatibility.
Install the software
Ensure the software is installed. In some cases you need to run an installer and in others you simply need to unpack a compressed .zip or equivalent. Then locate the directory that needs to be added to the Environment Variable. Typically this is named "bin". The optimal way to get this right is to navigate to a file inside the bin directory. Right click any file within the "bin" and select "Properties" from the context menu and then copy (Ctrl^C) the "Location". You can alternatively copy (Ctrl^C) the address (url) in the Windows Explorer address bar if you are currently in the "bin". In the case of Java, it should look similar to the image below:
Edit System or Environment Variables
Locate your existing PATH by going to to: Start => (Type) "env" into the search box => Select "Edit the system environment variables":
Create a PATH variable in uppercase if one doesn't exist
Select the 'PATH' variable or create a 'New...' one:
Add the Variables Value
Paste (Ctrl^P) the value you copied in step 1 to the end of the PATH. The existing PATH values and new ones must be separated by a semicolon(;). For this reason it is a good idea to always add an extra semicolon to the end of the PATH when done, so that you don't break your system when you add a new value next time:
Restart your Environment
If you added the PATH as a system and not environment variable then restart Windows. This option is not available to regular users (you must be admin to set system wide variables).
Testing the PATH
To ensure that the PATH is correct, attempt to launch one of the programs in the bin (if any) e.g., java -version command and should be able to view it through the echo %PATH% command.