Technology

Installing Java on CentOS 7

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.

  1. Login to your CentOS node.
  2. 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"
  3. Let’s install the rpm package.
    rpm -ivh *.rpm
  4. Execute
    vi ~/.bashrc
  5. and add the following lines to the file:
    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/
  6. Make sure the changes in bashrc are in effect:
    source ~/.bashrc
  7. Choose appropriate java and javac alternatives after executing the following commands.
    alternatives --config java
    alternatives --config javac
  8. You can check the java that’s currently being used, by executing the following commands.
    java -version
    javac -version

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.

Leave a Reply

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