Java is one of the most popular programming language. It is owned by Oracle and used to build different kinds of applications. We will install various versions of the Java Runtime Environment (JRE) and the Java Developer Kit (JDK). Also, we will install OpenJDK from official packages from Oracle. In this tutorial, you will learn how to install Java on Ubuntu 18.04 system.
You should logged in on Ubuntu 18.04 server using non-root user account with sudo privileges.
Install Default OpenJDK
Java installation process is easy and straight forward. OpenJDK 8 JDK is available to install from the standard Ubuntu repositories. Run the below command to install:
First update the package manager index using below command:
sudo apt update
Now install Java by typing following command:
sudo apt install default-jdk
Once the installation is finished you can confirm installation by checking version of jdk by:
It will show below output:
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)
All done! Java is installed on you Ubuntu system.
Install Specific Version of OpenJDK
Currently, latest stable version is OpenJDK 11. You can install OpenJDK with your specified version. You just have to add version as per below syntax.
sudo apt install openjdk-[VERSION]-jdk
For example, latest stable version is OpenJDK 11. So we can install it using below command:
sudo apt install openjdk-11-jdk
Installing Java From Oracle
Oracle provides license permits only non-commercial use, for personal use and development use only. So before going to install it read the Oracle JDK License. Here we are going to install Java 11.
Follow the below steps to install Java 11 from Oracle:
At first, we install the necessary dependencies using below command:
sudo apt install software-properties-common
Now you need to enable Linux Uprising PPA using following commands:
sudo add-apt-repository ppa:linuxuprising/java
Once the repository is added and enabled, update the packages list index:
sudo apt update
Next, run the below command to install package:
sudo apt install oracle-java11-installer
You will be prompted to accept and agree for the Oracle license. Accept it to continue installation.
Check the installed version by running the following command:
It will show you output as below:
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
Setting up default Java Version
If your Debian system have multiple version of Java then you can set default version as per your choice.
First, check the current default version by typing:
To change the default version use the
update-alternatives system command as below:
sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press to keep the current choice[*], or type selection number:
You can see list of all installed Java versions. Select appropriate selection number to set as default version.
You can uninstall the Java package same as other packages. For example, if you want to uninstall the
default-jdk package simply run:
sudo apt remove default-jdk
You have learned How to install and manage multiple Java versions on Debian 9 system. At the end you also learned how to set default Java version.
If you have any queries regarding this tutorial feel free to comment below.
Leave a Reply