How to Install Java on Ubuntu 20.04
Java is a high level, robust, object-oriented and secure rogramming language.Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995.Java runs on all major operating systems and devices.
In this Article we will discuss how to install java on ubuntu 20.04 system.
Also Read -> How to Install Docker on Ubuntu 20 04
Step 1: Install Java
First we will update the repo with apt and install openJdk 14
sudo apt update
sudo apt install openjdk-14-jdk
once it is installed, check java version with following command.
java -version
output:
openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 14.0.2+12-Ubuntu-120.04, mixed mode, sharing)
Also Read -> How to Install GO on Ubuntu 20 04
Step 2: install multiple versions of Java
you can install multiple versions of java. Here we will install openjdk 11 with the following command.
sudo apt install openjdk-11-jdk
install open jdk 8
sudo apt install openjdk-8-jdk
Step 3: Setup default Java version
you can setup default java version using the update-alternatives command.
sudo update-alternatives --config java
Also Read -> How to Install Flask on Ubuntu 20 04
output:
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-14-openjdk-amd64/bin/java 1411 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-14-openjdk-amd64/bin/java 1411 manual mode
3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode
Now check java version
java --version
output:
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
Also Read -> How to Install Apache Kafka on Ubuntu 20 04
Step 4: Setup Java environment variable
To set Java environment variable, we can check where java is installed by running the below command.
readlink -f /usr/bin/java
ouput:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
now open /etc/environment file usig nano or vi editor
sudo nano /etc/environment
add below line at the end of the file to above file.
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
save the file and exit.
Now reload the file to effect changes on your current shell.
source /etc/environment
verify Java environment variable with following command.
echo $JAVA_HOME
output:
/usr/lib/jvm/java-11-openjdk-amd64
That's it. Now we have successfully installed Java on Ubuntu 20.04 system.
Also Read -> How to Install MySQL 8 on Ubuntu 20 04