How To Install Oracle Java 12 / 11 / 8 on CentOS 6 / RHEL 6

0

ADVERTISEMENT

Today we will be looking into the installation of Oracle Java on CentOS 6.

Java JDK is the most important base to the developers; this guide will be more useful for them to set up a development environment when they especially use Red Hat or CentOS.

Download Oracle Java

You can either use command line or browser to download the JDK, better to use the browser, the easiest one. Visit the Oracle JDK page to download.

If you still want to use the command line, use the wget command to download packages.

### Oracle Java 12 ###

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.tar.gz

### Oracle Java 11 ###

LOGIN REQUIRED

### Oracle Java 8 ###

LOGIN REQUIRED

Extract and move to the desired location. In my case, it is /usr.

### Oracle Java 12 ###

tar -zxvf jdk-12.0.1_linux-x64_bin.tar.gz

### Oracle Java 11 ###

tar -zxvf jdk-11.0.3_linux-x64_bin.tar.gz

### Oracle Java 8 ###

tar -zxvf jdk-8u211-linux-x64.tar.gz

Move it to /usr.

mv jdk* /usr

Install Oracle Java

Once moved the java to the desired location, java must setup with the alternatives command. This will install the java on your system.

### Oracle Java 12 ###

update-alternatives --install /usr/bin/java java /usr/jdk-12.0.1/bin/java 1

### Oracle Java 11 ###

update-alternatives --install /usr/bin/java java /usr/jdk-11.0.3/bin/java 2

### Oracle Java 8 ###

update-alternatives --install /usr/bin/java java /usr/jdk1.8.0_211/bin/java 3

Set Default Java Version

Run the below command to set the default Java version on your system.

/usr/sbin/alternatives --config java

Select the java version you want to set as the default. I chose Oracle Java 11 as the default version.

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
   2           /usr/jdk-11.0.3/bin/java

Enter to keep the current selection[+], or type selection number: 2

Verify Java

Once you set up the default Java, verify it using the following command.

java -version

Output:

java version "11.0.3" 2019-04-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.3+12-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.3+12-LTS, mixed mode)

The output will vary depending upon the Java version.

Setup Environmental Variable

You may need to set up environment variables before the installation of any java based applications.

export JAVA_HOME=/usr/jdk-11.0.3/

Set PATH variable too.

export PATH=$JAVA_HOME/bin:$PATH

To set variables permanent, place the above three commands in the /etc/profile (All Users) or .bash_profile (Single User).

ADVERTISEMENT

Conclusion

That’s All. I hope this helped. Place your valuable comments below.

You might also like