Installing Oracle Java SDK in CentOS 7
Before starting I want to point out that all the commands required below must be executed as super user. By default CentOS doesn’t add the newly create users to the sudoers list, because of this, we will have to become super user using the command su
that will keep the root session open.
Downloading the binaries
Removing OpenJDK
to know which version you have to remove type yum remove java-
and then press tab for autocompletion. In CentOS 7, yum remove java
also does the job.
Installing the Oracle JDK rpm
For this example I will assume that the files are downloaded in /tmp/
By default this will be installed in /usr/java/jdk{version}
using a symbolic links, this will be mapped to /usr/java/default
that can be changed to a different SDK if required. To see the symbolic links, type the following in the shell:
this will return /usr/java/default -> /usr/java/latest
if we repeat the same operation, with the target of the symbolic link:
It will show the actual directory where the JDK is installed /usr/java/latest -> /usr/java/jdk1.7.0_71
. Changing this symbolic link would allow us to point to a different JDK without any extra effort.
I will do the same with the JDK 8 to have both versions on the server
In CentOS there is no need to redefine the alternatives for the java binaries, because they are defined already based on the default path (/usr/java/default
) so all the java commands will be available (java, jar, javaws, …).
Defining environment variables
Depending on the use, some users, just define the JAVA_HOME variable in their bash profile /home/{username}/.bashrc
adding it the following line:
In my case I intent to use the machine as a server so I want it to be defined for all the profiles, to achieve this, I create an sh
file in the folder /etc/profile.d/
where it will be always loaded on startup. This can be done with the following command:
Notice that this requires the OS to restart to be able to see the effects. Once this is done, you should be able see the value of JAVA_HOME with:
Now we have Oracle Java SDK installed on the system.