Set Java Path Linux Example

Set Java Path Linux Example

In this example we will set Java path in command line which will be avaible only for current command including we will also set path which will be permanent for all users:

Set Java path for current command:

  • First find where is Java installed and located:
$ locate JDK
/apps/java/jdk1.7.0_45-64/db/README-JDK.html
/apps/java/jdk1.8.0_51/db/README-JDK.html
  • As you see above we used “locate” command to find out where is JDK installed and what are the version. So we found two version of JDK is installed. Let’s say if you want to set “jdk1.8.0_51” path then do below:
bash-4.1$ export JAVA_HOME="/apps/java/jdk1.8.0_51"
bash-4.1$ echo $JAVA_HOME
/apps/java/jdk1.8.0_51
bash-4.1$ export PATH=$JAVA_HOME/bin:$PATH
bash-4.1$

That’s it for set path in current command. 

  • Now to set path permanently for all users please do below:
bash-4.1$ vi /etc/profile

then add below in this: 

export JAVA_HOME="/apps/java/jdk1.8.0_51"

export PATH=$JAVA_HOME/bin:$PATH
  • Reference:

Oracle: PATH and CLASSPATH

Leave a Reply

Your email address will not be published. Required fields are marked *