I recently installed Oracle Linux 7.2 in VirtualBox. I tried to install some software but was not able to due to the Java Product installed. I found that OpenJDK was installed by default, whereas I required Oracle JDK. So below are the steps to replace OpenJDK with Oracle JDK.
1. Confirm the version of JDK installed:
2. Run the following yum command to remove OpenJDK. The command will remove all Java packages:
yum -y remove java*
3. 'java -version' should no longer display the currently installed java version.
4. Download the version of the Oracle JDK you want to install as a rpm:
I will be downloading Java 8 Update 144. You can download from Oracle's website here or use wget to download from the Terminal. Following wget command downloads the version I need:
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm
If you download the rpm manually, then copy the .rpm over to the Oracle Linux machine (For example, through Shared Folder if using Virtual Box).
5. Change directory to where the JDK rpm is downloaded and run the following command to install the Oracle JDK:
rpm -ivh jdk-8u144-linux-x64.rpm:
This will install the update 144 of java 8.
Run command 'java -version' to verify:
Note that java will be installed into /usr/java and establish softlinks as follows:
# ll /usr/java
lrwxrwxrwx. 1 root root 16 Jun 17 18:48 default -> /usr/java/latest
drwxr-xr-x. 8 root root 4096 Jun 17 18:48 jdk1.8.0_144
lrwxrwxrwx. 1 root root 21 Jun 17 18:48 latest -> /usr/java/jdk1.8.0_144
To set JAVA_HOME environment variable, do the following:
You can set your JAVA_HOME in /etc/profile but the preferred location for JAVA_HOME or any system variable is /etc/environment.
Open /etc/environment in any text editor like nano or gedit:
Add the following line:
(java path could be different)
Use source to load the variables, by running this command:
Then check the variable, by running the echo command on the variable: