How To Install Java with Apt on Ubuntu 18.04?

Install Java On Ubuntu

This article enlightens you with necessary information of installing java. Java is one of the most popular programming languages in software world, used for building different types of cross-platform applications. Java offers the possibilities that the majority programs is written during a type-safe language. However, for Java to be broadly helpful language, it must have a lot of communicatory power than it will at the moment. This paper addresses one in every of the areas wherever a lot of power is required. It extends Java with a mechanism for constant polymorphism, that permits the definition and implementation of generic abstractions. The paper offers a whole style for the extended language. The projected extension is little and conservative and therefore the paper discusses the explanation for several of our choices. The extension will have some impact on alternative elements of Java, particularly Java arrays, and therefore the Java category library.

This tutorial describes how to install various versions of OpenJDK as well as Oracle Java on Ubuntu 18.04. The same instructions apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS. Java is distributed in three different editions, Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). OpenJDK and Oracle Java are the two main implementations of Java, with almost no differences between them except that Oracle Java has a few additional commercial features.

There are two different Java packages in Ubuntu repositories, Java Runtime Environment (JRE), and the Java Development Kit (JDK). If you only want to run Java programs, then you need JRE, which contains only the Java Runtime Environment. Java developer should install JDK, which also includes the development/debugging tools and libraries. They will show you how to install various Java packages. If you don’t know which Java implementation or version to use, the general recommendation is to stick with the default OpenJDK version available on Ubuntu 18.04.

Verify the installation

You can verify the installation process by running the command which will print the Java version. The objective of this tutorial is to install Java on Ubuntu. We will be installing the latest version of Oracle Java SE Development Kit (JDK) on Ubuntu 18.04 Bionic Beaver Linux. This will be performed in three ways: Installing Java using the Ubuntu Open JDK binaries, installing Java via PPA and installing Java using the official Oracle Java binaries. In most cases you do not need to look further to install Java on Ubuntu than Ubuntu's repository which contains an open source version of Java runtime binaries called Open JDK.

In this guide, you'll install varied versions of the Java Runtime surroundings (JRE) and also the Java Developer Kit (JDK) victimisation apt . You’ll install OpenJDK moreover as official packages from Oracle. You’ll then choose the version you want to use for your comes. once you are finished, you’ll be able to use the JDK to develop computer code or use the Java Runtime to run computer code.

Java and also the JVM (Java’s virtual machine) are wide used and needed for several types of computer code. this text can guide you thru the method of installing in and managing totally different versions of Java apt-get. You have currently put in Java and knowledge to manage totally different versions of it. you'll currently install needed software code that runs on Java, like Tomcat, Jetty, Glassfish, Cassandra, or Jenkins. It’s a fairly easy and straightforward method, and we’ll show you piecemeal directions on the way to install Java on Ubuntu. These directions can work for Ubuntu 16.04, 18.04, Ubuntu 20.04, and the other LTS unharness, or perhaps different Ubuntu-based distros like Xubuntu. This should work for any Ubuntu-based distro, even non-LTS versions like 20.10, however they were tested on Ubuntu 18.04 and Ubuntu 20.04. They must work on each servers and desktops.

You should know the things before you start to installing Java. Have a tendency to install java, it will help you to get a perfect idea to install java easily. It is an Ubuntu server, definitely you will get one from Vultr or the other cloud hosting supplier by using it. A sudo/root user helps to all commands in java are dead by the basis user. If you are employing a non-root user then you’ll have to be compelled to append ‘sudo’ to most commands. An SSH shopper like MobaXterm, if you employ Windows, or SSH enabled if you employ Ubuntu. Make sure you do not have Java already put in. If you do, remove it, or if you would like to use multiple Java versions/installs, then keep it and assemble them later. So that’s just about it.

The below mentioned installing guides are also suitable for Ubuntu 18.04.

Requirement:

To install java in your Ubuntu, it is mandatory to logged in as a user with sudo privileges.

Java Variations:

Java is available in three different editions. They are listed as follows.

  • Standard Edition
  • Enterprise Edition
  • Micro Edition

Standard edition is the common choice of many developers and you will the guide to install it below.

OpenJDK and Oracle Java are the implementations available in Java. Oracle Java possess few additional commercial features than OpenJDK, other than that, there is no big difference between these two implementations.

In general, there are two different packages available in Java for Ubuntu repositories. They are Java Runtime Environment (JRE) and Java Development Kit (JDK).

JRE is suitable for those who needs to run java programs but developers need to install JDK which encompasses development and debugging tools along with its libraries.

Since numerous versions available, it always baffles developers to make a decision. If you are strangled then it is better to adherer to default OpenJDK version in Ubuntu 18.04.

How to install Default OpenJDK or Java11?

This is the latest LTS version of java and the following steps aids you installing Java OpenJDK 11 on your Ubuntu system.

Step 1:

Updating apt package index is the first step and for that use

$ sudo apt update

Step 2:

When the package index is updated, it is time to install default Java OpenJDK package. For that,

$ sudo apt install default-jdk

Step 3:

It is mandatory to verify the installation, use this following command and it will print the Java Version.

$ java -version

When you run this command, it will display the following output.

Output:

openjdk version "11.0.2" 2020-10-23

OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)

OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)

When it displays, it refers you have successfully installed Java on your Ubuntu system.

JRE encompassed in JDK package. If you are only interested in JRE, then stick to the default-jre package to install.

Installing OpenJDK 8:

Java 8 is one of the widely employed version of Java. It is simple to install Java * by running few commands. They are listed as follows.

$sudo apt update

$sudo apt install openjdk-8-jdk

This command helps you get the job done.

Installing Oracle Java:

When you want to install Oracle Java, it is better to read Oracle JDK license. In their license, they have mentioned that, they only permits non-commercial use of the software. If are allowed to use this app for personal use and development use but not commercial use. Going through the entire license is worth considering option.

Linux Uprising PPA can be used to install Oracle Java 11.

The below mentioned steps aids you learn more about the ways of installing Oracle Java 11 on Ubuntu 18.04.

Step 1:

The dependencies mandatory to add new repository has to be installed first. Follow this command to install it.

sudo apt install software-properties-common

Step 2:

Enabling Linux Uprising PPA is the next step to concentrate on. To run it, follow the below mentioned command.

Sudo add-apt-repository ppa:linuxuprising/java

Step 3:

When you are done with adding repository, then next thing to follow is updating the package and installing oracle-java11-installer package. To install this package, employ the below mentioned command.

$sudo apt update

$sudo apt install oracle-java11-installer

Now you are prompted to procure the Oracle license.

Step 4:

To verify the installation, you have to run the below mentioned command. Running this command will print R version.

$java -version

The output will displayed seems like below mentioned.

java version "11.0.2" 2020-10-23 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)

If you are using the default version of Java, then the following command aids you more.

$ java -version

Its output is displayed like below.

openjdk version "11.0.2" 2019-01-15

OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)

OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)

When you have installed multiple java installation, then you can change to default version. The command to change default are listed below and you need to use update-alternatives tools.

$sudo update-alternatives --config java

It will display the following output.

There are 3 choices for the alternative java (providing /usr/bin/java).

SelectionPathPriorityStatus

------------------------------------------------------------

* 0/usr/lib/jvm/java-11-openjdk-amd64/bin/java1111auto mode

1/usr/lib/jvm/java-11-openjdk-amd64/bin/java1111manual mode

2/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java1081manual mode

Press <enter> to keep the current choice[*], or type selection number:

When it displays the output, you can change the java version easily. All you need to do is to entre the version number mentioned in the selection column and hit Enter.

Tips to set JAVA_HOME Environment variable:

Many of the applications developed employing JAVA are using JAVA_HOME Environment variable to estimate the installation location of the Java.

Fishing out the Java Installation paths are the foremost thing to concentrate on when it comes to setting JAVA_HOME environment variable. It can be found by using the command update-alternatives.

$sudo update-alternatives --config java

It will display the java installed paths. Now copy the installation paths which you are interested and now open the /etc/environment file.

$sudo nano /etc/environment

At the end of the file, insert the below mentioned line.

/etc/environment

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

It is mandatory to ensure that you have replace the path with path to the chosen Java version.

To make changes to the current sessions, you have to run the source command. It can assist you log in or log out and make the changes you havedesired.

$source /etc/environment

When it comes to verify the JAVA_HOME environment variable and how correctly it has been set, you have to follow the echo command.

$echo $JAVA_HOME

It will display output like it is mentioned below.

/usr/lib/jvm/java-11-openjdk-amd64

The above mentioned is the effectual way to install Java.

For your additional information, the details of uninstalling Java are also mentioned below.

When you want to uninstall Java Package, just like uninstalling package you have to uninstall the apt.

For your better understanding, you can uninstall the openjdk-8-jdk package run. The following command will help you.

$sudo apt remove openjdk-8-jdk

I hope this article enlightens your path of installing multiple Java versions on Ubuntu server and you must have got the information you are searching for.


Learn more :

Basic Linux Commands For Every User To Access The Operating System

How Can VPN work? The major function of VPN

Start now for as low as $4,99 a month!

  • 8 Characters2
  • 1 Uppercase Atleast
  • 1 Number Atleast