Install Java 8 on CentOS
This guide will show you how to install or update Java 8 on your system. Before downloading Java through the Linux command line, make sure you read the instructions thoroughly.
Table of Contents
Oracle Java 11 is by far the most latest LTS version that can be downloaded and installed. Follow the steps below to install Oracle Java 11 on CentOS and Fedora systems.
Step 1: Download Latest Java SE Development Kit 8
Oracle provides both Java RPM packages and compiled source code. I’ve tried installing Java using rpm packages several times, but I’ve always run into problems. As a result, I choose to install Java from the compiled source code. Since then, I’ve successfully installed Java on CentOS and Redhat-based systems several times. To download the latest Java SE Development Kit 8 release, go to its official download page or use the shell commands below.
cd /opt/
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz"
tar xzf jdk-8u201-linux-x64.tar.gz
Step 2 – Install Java 8 with Alternatives
The alternatives command is used for maintained symbolic links. This command used to creates, removes, maintains, and display information about the symbolic links comprising the alternatives system. Let’s use the alternatives command to configure Java on your system. The alternatives command is available in chkconfig
package.
cd jdk1.8.0_201/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_201/bin/java 2
alternatives --config java
The number 4 corresponds to the newly installed Java version, so type 4 and hit enter.
Select java version
There are 3 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 /opt/jdk1.8.0_45/bin/java
* 2 /opt/jdk1.8.0_144/bin/java
+ 3 /opt/jdk-11/bin/java
4 /opt/jdk1.8.0_201/bin/java
Enter to keep the current selection[+], or type selection number: 4
JAVA 8 has now been successfully installed on your system. We also propose utilizing alternatives to set up the javac and jar command paths.
alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_201/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_201/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_201/bin/jar
alternatives --set javac /opt/jdk1.8.0_201/bin/javac
Step 3: Verify the Installed Version
The PATH environment variable makes Java and javac binaries available. They can be accessed from any location on your system. Let’s see what version of the Java runtime environment (JRE) is installed on your system by running the command below.
java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
Step 4: Configure Java Environment Variables
The majority of Java-based applications rely on environment variables to work. Set the Java environment variables with the commands below.
Set the environment variables JAVA_HOME, JRE_HOME, and PATH.
export JAVA_HOME=/opt/jdk1.8.0_201
export JRE_HOME=/opt/jdk1.8.0_201/jre
export PATH=$PATH:/opt/jdk1.8.0_201/bin:/opt/jdk1.8.0_201/jre/bin
Add the above commands to /etc/bashrc or /etc/environment
to have the environment variables set automatically when the system reboots.
Saad Shafqat
Related posts
New Articles
Getting Around: 9 Top Keyboard Shortcuts for Mac
As easy to use as Macs are, there’s always room for improvement in the user-friendly department. Case in point: Mac…