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:; oraclelicense=accept-securebackup-cookie" ""
  3. Let’s install the rpm package.
    rpm -ivh *.rpm
  4. Execute
    vi ~/.bashrc
  5. and add the following lines to the file:
  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 *