Java is a very famous, general-purpose programming language that is used for creating applications that run on mobile devices as well as computers. It can create applications that can run on a single system as well as can be distributed among servers & clients in a network. In this tutorial, we will learn to install JAVA on Ubuntu systems.
Recommended Read: How to setup SSH login without password on Linux systems
Also Read: How to install Java on CentOS & RHEL
Before we learn how to install JAVA on Ubuntu, we must know the types of java available to install. There are two different types of java versions we can install.
Two versions being,
JAVA JRE (Java Run Time Environment) – JRE is used when you only need to run java based applications.
JAVA JDK (Java Development Kit) – is used for developing Java-based applications. It included JRE, debugging tool & some other libraries.
Moreover, there are two types of java available that we can install OPENJDK Java & Oracle java. Both are similar & provide almost the same functionalities barring for some additional features in Enterprise versions. We will learn to install both the java types in this tutorial.
OpenJDK installation
Java 11
To install OpenJDK java on Ubuntu, we need to execute the following commands from the terminal,
$ sudo apt-get update
$ sudo apt-get install default-jdk
This will install the default java JDK i.e. version 11 on Ubuntu system. If we need to install the java 11 jre, then we need to execute the following command,
$ sudo apt install default-jre
Java 8
To install java 8 on the systems, we need to run the following command,
$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk
& to install JRE, use the following command,
$ sudo apt-get install openjdk-8-jre
Oracle Java Installation
Oracle Java is not available on the default Ubuntu repositories & we need to install other custom repositories to be able to install java on Ubuntu. Install the repository first with the following command,
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:linuxuprising/java
Next update system repositories,
$ sudo apt-get update
& install java on Ubuntu system,
$ sudo apt-get install oracle-java11-installer
Java is now installed on the system. The next part is configuring the default java for the systems as you might have more than one java version installed on the system.
Configuring default Java
Command to configure the default java is,
# alternatives –config java
Then you should get the java versions installed on the system, type the number mentioned against the java version & press enter to make it the default versions. This will change the java versions to one that you want. We end this tutorial on how to install java. Please do let us know if you have questions, queries or suggestions using the comment box below.