JDK installation in linux (Ubuntu, Centos)


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

https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html


To download jdk for now, you need:


  1. go to link above.
  2. create account if you do not have
  3. download latest JDK8 version

https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

  1. copy jdk archive into ${HOME} directory.


Latest for now is: 8u321


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

$ tar -xvzpf jdk-8u321-linux-x64.tar.gz
$ sudo mv jdk1.8.0_321/ /opt/
$ sudo ln -s /opt/jdk1.8.0_321/ /opt/jdk


$ rm jdk-8u321-linux-x64.tar.gz


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


#### JDK 1.8 #######################

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

#### JDK 1.8 #######################


$ sudo chmod 755 /etc/profile.d/java8.sh
$ source /etc/profile.d/java8.sh


Let try to check result:


$ java -version
java version "1.8.0_281"


OpenJDK installation in linux (I recommend do not use OpenJdk without reasons)


$ sudo apt-get update
$ sudo apt-get install -yq openjdk-8-jdk

// get possible jdk locations
$ sudo update-alternatives --config java

// specify jdk location
$ sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

$ java -version


also you can install maven from packages

$ sudo apt-get install -yq maven