This article is more for my own reference, as I keep forgetting the steps for installing Java on CentOS. The procedures are pretty straightforward. I’ll be assuming it’s CentOS 7(.4) and Java SE 8 is what we’re going to install. I’m also going to assume, the installation is done as the root user. If you’re planning to install as non-root user, you might have to use sudo for some of the following commands. Here we go.
- Login to your CentOS node.
- Download the rpm binary using the following command:
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/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.rpm"
- Let’s install the rpm package.
rpm -ivh *.rpm
- Execute
vi ~/.bashrc
and add the following lines to the file:
- Make sure the changes in bashrc are in effect:
source ~/.bashrc
- Choose appropriate java and javac alternatives after executing the following commands.
alternatives --config java alternatives --config javac
- You can check the java that’s currently being used, by executing the following commands.
java -version javac -version
JAVA_HOME=/usr/java/jdk1.8.0_192-amd64 JRE_HOME=/usr/java/jdk1.8.0_192-amd64/jre PATH=$PATH:/usr/java/jdk1.8.0_192-amd64/bin:/usr/java/jdk1.8.0_192-amd64/jre/bin/
And voila! We’re done. As you might have noticed, this instruction is for Java 8u192. If you’re going to install a different version, just change the version tag accordingly in steps 2 and 4. Good luck.