The following command will return a list of all packages directly related to Java. They will be in the format of java-<version>.
$ yum search java | grep 'java-'
If there are no available packages, then you may need to download a new repository to search through. I suggest taking a look at Dag Wieers' repo. After downloading it, try the above command again.
You will see at least one version of Java packages available for download. Depending on when you read this, the lastest available version may be different.
java-1.7.0-openjdk.x86_64
The above package alone will only install JRE. To also install javac and JDK, the following command will do the trick:
$ yum install java-1.7.0-openjdk*
These packages will be installing (as well as their dependencies):
redhat docs are always a great source - good tutorial that explains how to install JDK via yum and then setting the path can be found here (have fun!) - Install OpenJDK and set $JAVA_HOME path
OpenJDK 6:
yum install java-1.6.0-openjdk-devel
OpenJDK 7:
yum install java-1.7.0-openjdk-devel
To list all available java openjdk-devel packages try:
Step -3) Install the java8 using below command
sudo yum localinstall jdk-8u121-linux-x64.rpm
Now the JDK should be installed at
/usr/java/jdk1.8.0_121
Step -4) Remove the downloaded .rpm file to utilize the space.
rm jdk-8u121-linux-x64.rpm
Step -5) Verify the java by using command
java -version
Step -6) If the CentOS has multiple JDK installed, you can use the alternatives command to set the default java
sudo alternatives --config java
Step -7)Optional set JAVA_HOME Environment variables.
copy the path of jdk install i.e /usr/java/jdk1.8.0_121
use below command to export java home
export JAVA_HOME=/usr/java/jdk1.8.0_121
export PATH=$PATH:$JAVA_HOME
First, I downloaded the .tar file for Java JDK and JRE from the Oracle site.
Extract the .tar file into the opt folder.
I faced an issue that despite setting my environment variables, JAVA_HOME and PATH for Java 9, it was still showing Java 8 as my runtime environment. Hence, I symlinked from the Java 9.0.4 directory to /user/bin using the ln command.
I used java -version command to check which version of java is currently set as my default java runtime environment.