JDK installation in linux (Ubuntu, Centos)

To download jdk for now, you need:

1) go to java.sun.com (browser will redirect you to right path). 2) create account if you do not have 3) download latest JDK8 version 4) copy jdk archive into ${HOME} directory.


Install packages for installation

// Ubuntu
$ sudo apt-get install -y \
vim \
unzip \
tar \
wget


// Centos
$ sudo yum install -y \
vim \
unzip \
tar \
wget


Installation JDK8 in linux

$ ls jdk*
jdk-8u211-linux-x64.tar.gz

$ tar -xvzpf jdk-8u211-linux-x64.tar.gz
$ sudo mkdir -p /opt/jdk/1.8.0_211
$ sudo mv jdk1.8.0_211/* /opt/jdk/1.8.0_211/
$ sudo ln -s /opt/jdk/1.8.0_211/ /opt/jdk/current


$ rm -rf jdk1.8.0_211/
$ rm -rf jdk-8u211-linux-x64.tar.gz


$ sudo vi /etc/profile.d/java.sh


#### JDK 1.8.0 #######################

export JAVA_HOME=/opt/jdk/current
export PATH=${JAVA_HOME}/bin:$PATH

#### JDK 1.8.0 #######################


 $ source /etc/profile.d/java.sh


Let try to check result:


$ java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)


OpenJDK installation in linux

$ sudo apt-get update
$ sudo apt-get install -yq openjdk-8-jdk
$ sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
$ java -version


$ sudo apt-get install -yq maven