We can install JDK with the binary file (.tar.gz
).
We need to make directory, where we need to install Java. For global access for all users, preferably in the directory /usr/java
mkdir /usr/java && cd /usr/java
We can download Java (JDK) 9 from Java Download
For reference, We can download the Source tarball file-name with given below
#jdk-9.0.4_linux-x64_bin.tar.gz
Alternatively, we can download with wget command as given below in to /usr/java
# cd /usr/java
# wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/9.0.4+11/c2514751926b4512b076cc82f959763f/jdk-9.0.4_linux-x64_bin.tar.gz
Extract tarball wite given below
#tar -zxvf jdk-9.0.4_linux-x64_bin.tar.gz
Use update-alternatives command to change the Java environment path
cd /usr/java/jdk-9.0.4/
For Java to select default
# update-alternatives --install /usr/bin/java java /usr/java/jdk-9.0.4/bin/java 100
# update-alternatives --config java
For Javac to select default
# update-alternatives --install /usr/bin/javac javac /usr/java/jdk-9.0.4/bin/javac 100
# update-alternatives --config javac
Similarly, update jar alternatives as
# update-alternatives –install /usr/bin/jar jar /opt/java/jdk-9.0.4/bin/jar 100
# update-alternatives –config jar
Setting up Java Environment Variables
# export JAVA_HOME=/opt/java/jdk-9.0.4/
# export JRE_HOME=/opt/java/jdk-9.0.4/jre
# export PATH=$PATH:/opt/java/jdk-9.0.4/bin:/opt/java/jdk-9.0.4/jre/bin
To Check java version from the linux
# java -version
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)