How To Install Java on Ubuntu 18.04

How To Set up Java on Ubuntu 18.04: A Full Step-by-Step Information


How to Install Java on Ubuntu 18.04

This text will educate you the best way to set up Java on Ubuntu 18.04. The instructions will work on any system operating the newest edition, Ubuntu 18.04 Bionic Beaver, in addition to 16.04, and another Lengthy Time Help (LTS) releases. Java is often distributed in three editions, specifically Micro (ME), Enterprise (EE), and Customary Version (EE). For this information, we’ll use Java SE 11 (LTS).

General, Java is likely one of the main programming languages on the earth. It’s created to have as little dependencies as potential, which permits utility builders to use the “write once, run anywhere” philosophy. Consequently, a compiled Java code can function on any platform which helps Java. You may put it to use to construct something from easy internet purposes to extra superior items of program.

With out additional ado, let’s see how we are able to set up Java on Ubuntu 18.04.


The OpenJDK (Java Improvement Equipment) and Oracle JRE (Java Runtime Atmosphere) are the 2 primary kits you’ll work with. Oracle Java comprises the JVM, the Java program, alongside different infrastructures, whereas the JDK is a superset of JRE. The JDK is basically an SDK (program improvement equipment), because it provides you entry to every little thing in JRE plus instruments comparable to jdb, javadoc, and the compiler itself – javac.

If you happen to’re not interested by compiling Java program, the JRE will do exactly effective. If this adjustments, you possibly can replace it later.

The next instructions suggest you might be already utilizing a root consumer, however in case you’re not, you must add sudo initially of your instructions.

Set up Java on Ubuntu Utilizing the Default Bundle Supervisor

The primary technique to put in Java on Ubuntu is thru the default packages. Start the method by updating the present packages to the newest edition:

apt-get replace && apt-get improve

As soon as it finishes, set up the newest edition of Java Runtime Atmosphere (JRE) by executing this following command:

apt-get set up default-jre

It is usually potential to put in the Java Improvement Equipment (JDK) as a substitute. It’s required by particular program or used to compile Java applications. JDK contains JRE, subsequently there’s no drawback in the event you select this technique as a substitute.

apt-get set up default-jdk

That’s it,2 Java is prepared to be used in your Ubuntu system. You may double-check if it was correctly arrange with these instructions:

java -version
javac -version

The output will probably be just like:

[email protected]:~# java -version
openjdk edition "11.0.6" 2020-01-14
OpenJDK Runtime Atmosphere (construct 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (construct 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, blended mode, sharing)
[email protected]:~# javac -version
javac 11.0.6

Set up Java on Ubuntu through Oracle JDK

Alternatively, it’s potential to put in Java on Ubuntu utilizing the official Oracle JDK. Start by updating your present packages to the newest edition:

apt-get replace && apt-get improve

For this instance, we’ll use a 3rd get together library managed by WebUpd8. With a purpose to implement it simpler, set up the next bundle first:

apt-get set up software-properties-common

Subsequent, get the Java Rebellion PPA with the next command:

add-apt-repository ppa:linuxuprising/java

You would possibly even wish to run a fast replace when you’re at it:

apt-get replace

Lastly, you possibly can set up Java in your Ubuntu system by executing the next command and following the on-screen directions:

apt replace; apt-get set up oracle-java14-installer

PRO TIP: The next command will set up Java edition 14. For an older edition, you could change the syntax to java13 or java11 and so forth.

That’s it! Java is efficiently put in. Chances are you’ll confirm it by checking the edition with these two instructions:

java -version
javac -version

An analogous output will seem:

[email protected]:~# java -version
java edition "14" 2020-03-17
Java(TM) SE Runtime Atmosphere (construct 14+36-1461)
Java HotSpot(TM) 64-Bit Server VM (construct 14+36-1461, blended mode, sharing)
[email protected]:~# javac -version
javac 14

Managing Java

A single server can have a number of Java installations. You may set the default edition utilizing the next command line:

update-alternatives --config java

The next output will seem:

There are 2 selections for the choice java (offering /usr/bin/java).

  Choice    Path                                         Precedence   Standing
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      handbook mode
* 2            /usr/lib/jvm/java-14-oracle/bin/java          1091      handbook mode

Press  to maintain the present alternative[*], or sort choice quantity:

Enter the quantity from the choice menu which you want to use because the default one. You too can do that with different Java instructions, comparable to:

update-alternatives --config javac
update-alternatives --config javadoc
update-alternatives --config jarsigner

Setting the Java House Atmosphere

One other helpful factor to know is the best way to set the JAVA_HOME variable. Most purposes require it to search out the situation of your Java set up. The beforehand used command may also help you find the Java set up path:

update-alternatives --config java
listed here are 2 selections for the choice java (offering /usr/bin/java).

 Choice  Path                     Precedence  Standing
 0      /usr/lib/jvm/java-11-openjdk-amd64/bin/java  1111   auto mode
 1      /usr/lib/jvm/java-11-openjdk-amd64/bin/java  1111   handbook mode
* 2      /usr/lib/jvm/java-14-oracle/bin/java     1091   handbook mode

Press  to maintain the present alternative[*], or sort choice quantity: 

When you’ve copied the set up path, you will want to edit the setting file situated within the and so forth listing:

nano /and so forth/setting

Add the next line on the finish to set the JAVA_HOME worth:


NOTE: Don’t neglect to replace it with the precise path to your Java set up.

Press CTRL+X to complete modifying and save the adjustments. Subsequent, make the adjustments by making use of this command:

supply /and so forth/setting

You may double-check if it’s energetic by getting into:


Additional Studying

Try these articles for extra in-depth VPS guides and administration tips:


Congratulations, you now know the best way to set up Java on Ubuntu 18.04. You’ve additionally realized some fundamentals, comparable to setting the default Java edition and defining the JAVA_HOME variable.

If you happen to discovered this text helpful, be happy to share it with the world. When you have any suggestions, strategies, or concepts of your individual, we eagerly await them within the remark part under.


Edward is Hostinger’s copywriter. He is an professional communicator with years of expertise in IT as a author, marketer, and Linux fanatic. IT is a core pillar of his life, private {and professional}. Edward’s purpose is to encourage hundreds of thousands to attain an impactful on-line presence. He additionally actually loves canine, guitars, and every little thing associated to house.

READ  assessment - Techpix

Leave a Reply

Your email address will not be published. Required fields are marked *