The PATH variable gives the location of executable files. It is possible to run a program without specifying the PATH but you will need to give full path of executable like %SystemRoot%\TEMP instead of using TEMP or TMP variable.
How to set Environment Variables in Java: Path and Classpath
In Windows
The CLASSPATH variable gives location of the Library Files.
Let’s look into the steps to set the PATH and CLASSPATH
-
Right Click on the My Computer and select the Properties.
Note:
Some haveThis PC
name forMy Computer
whereas you have to run by Administrator Privileges. -
Click on Advanced system settings.
-
Click on Environment Variables
-
Click on
New...
Button of User variables. -
Type PATH in the Variable name field.
-
Copy the path location of bin folder where JDK is installed.
-
Paste path location of bin folder in Variable value and click on
OK
Button.
In Linux
Let’s see how to set path in Linux OS:
$ export PATH=$PATH:/home/jdk1.6.01/bin/
In Ubuntu Linux
Edit the system Path file /etc/profile
$ sudo gedit /etc/profile
Add following lines in end.
JAVA_HOME=/usr/lib/jvm/jdk1.x.x -- Where your JDK is installed
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
$ source /etc/profile
Verify the output.
- Open a terminal and run the following command:
$ javac -version
Continue
Proceed to Lab 1 - First Program.