- Visit Oracle JDK download page, look for RPM version.
- Copy the rpm link and wget it
wget --header "Cookie: oraclelicense=accept-securebackup-cookie" Download link.rpm
Note: Install wget if missing
sudo yum install wget -y
- Install oracle jdk8
sudo yum localinstall jdk8 downloaded package name.rpm
- Verfication
java -version
- Delete the rpm file
rm ~/jdk8 downloaded package name.rpm
- Set Environment variables This is good practice to set the JAVA_HOME environment variable. 6.1 Edit the .bash_profile, and append the export JAVA_HOME at the end of the file, for example :
.bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export JAVA_HOME=/usr/java/jdk1.8.0_102/
export JRE_HOME=/usr/java/jdk1.8.0_102/jre
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export PATH
6.2 Test the $JAVA_HOME and $PATH
$ source .bash_profile
$ echo $JRE_HOME
/usr/java/jdk1.8.0_102/jre
$ echo $JAVA_HOME
/usr/java/jdk1.8.0_102/
$ echo $PATH
/...:/usr/local/bin:/usr/X11R6/bin:/home/mkyong/bin:/usr/java/jdk1.8.0_102//bin
- If the RHEL has multiple JDK installed, you can use the alternatives command to set the default java
$ sudo alternatives --config java
[sudo] password for mkyong:
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
*+ 2 /usr/java/jdk1.8.0_102/jre/bin/java
Enter to keep the current selection[+], or type selection number: