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

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

  1. 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 JDK17 in linux


https://www.oracle.com/java/technologies/downloads/


$ cd ~/tmp
$ wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz


//
// $ sudo apt-get purge -y --auto-remove openjdk*


$ ls jdk*
jdk-17_linux-x64_bin.tar.gz

$ tar -xvzpf jdk-17_linux-x64_bin.tar.gz
$ sudo mv jdk-17.0.1/ /opt/
$ sudo ln -s /opt/jdk-17.0.1/ /opt/jdk


$ rm jdk-17_linux-x64_bin.tar.gz


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


#### JDK #######################

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

#### JDK #######################


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


Let try to check result:


$ java -version
java version "17.0.1" 2021-10-19 LTS


Installation JDK8 in linux

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


Latest for now is: 8u311


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

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


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


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


#### JDK #######################

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

#### JDK #######################


$ 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