DEV Community

Cover image for How to install JDK in Ubuntu 16.04, 18.04, (or) 20.04
N. V. Murali Krishna
N. V. Murali Krishna

Posted on

How to install JDK in Ubuntu 16.04, 18.04, (or) 20.04

Step 1: Update Ubuntu

$ sudo apt-get update

step 2: Download java jdk file

[https://www.oracle.com/java/technologies/javase-jdk14-downloads.html]
Go and Click : Linux compressed archive jdk-14.0.1_linux-x64_bin.tar.gz

step 3: Go to your downloads path:

$ cd Downloads

step 4: find your jdk fie and run this command to extract the jdk file

$ ls
$ tar -zxvf jdk-14.0.1_linux-x64_bin.tar.gz

step 5: Go to library file and here we creating java directory

$ cd /usr/lib/
$ sudo mkdir java

step 6: After creating java file move to your jdk file into java directory

$ cd ~/Downloads/
$ sudo mv jdk-14.0.1/ /usr/lib/java

step 7: Next go to java directory here we are successfully moved jdk file into java directory

$ cd /usr/lib/java/
$ ls
out put: jdk-14.0.1
$ cd jdk-14.0.1

step 8: Next run bellow the commands one by one :

Note: 14.0.1 is jdk version if in case u r download bellow version like 12.0.1 plz replace it

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/jdk-14.0.1/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk-14.0.1/bin/javac"
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/jdk-14.0.1/bin/javaws" 1

step 9: Update the JAVA_HOME in your ~/.bashrc

$ sudo gedit ~/.bashrc

output:
~/.bashrc: executed by bash(1) for non-login shells.
see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
for examples

If not running interactively, don't do anything...

like this.. go to file last column and add the java home

step 10: Add Java Home here

#JAVA HOME directory setup
export JAVA_HOME=/usr/lib/java/jdk-14.0.1
export PATH="$PATH:$JAVA_HOME/bin"

click : save

step 11: Finally we are install jdk successfully check it

$ javac
$ java
$ java -version

out put:
java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)

Top comments (0)