In this article we are going to see how to install different Java version on your linux system and also how to make it as a default one.

Installing through yum:

    When we install java directly the current version is JDK-1.8.0_181

$ yum install java

    To check the version of the Java use the below command,

$ which java

jhony@ljunix~$ which java
/usr/bin/java

$ java -version

jhony@ljunix~$ java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

    We can run our applications on different Java versions through source installation.

Installing through source:

    Download the latest file from the official site. Click the following link for downloading the latest version ORACLE.COM. You have to accept the License Agreement to get the download link for the required version.

Note: You cannot download the package through wget. It is recommended to download the package on your system and scp the tar file to the required server.

Untar the file:

$ tar -xzf jdk-8u191-linux-x64.tar.gz

Move the extracted file to /usr/local/ directory,

$ mv jdk1.8.0_191/ /usr/local/

Export the JAVA_HOME and PATH to the installed JDK,

$ export JAVA_HOME=/usr/local/jdk1.8.0_191
$ export PATH=$PATH:/usr/local/jdk1.8.0_191

To check the Java path try echo command,

$ echo $JAVA_HOME

jhony@ljunix~$ echo $JAVA_HOME
/usr/local/jdk1.8.0_191

    Now we have all set to run the application through the installed java by mentioning the Java path on the application's bin file.

    Java file path will be /usr/local/jdk1.8.0_191

Setting the default Java and Java Environment to the installed JDK:

    Before pointing the java to the souce installation file, unlink the existing java on /usr/bin which was installed through yum.

$ cd /usr/bin/

$ unlink java

Create a symlink on the /usr/bin/ directory for java and set the path to the installed JDK file,

$ ln -s /usr/local/jdk1.8.0_191/bin/java java

    Now your server's default java will be jdk1.8.0_191, check the version of java.

$ which java

jhony@ljunix~$ which java
/usr/bin/java

$ java -version

jhony@ljunix~$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

    Feel free to ask if you have any questions.

Comments

  1. Be the first to add a comment.