linuxize.com Open in urlscan Pro
2606:4700:20::681a:f0  Public Scan

URL: https://linuxize.com/post/install-java-on-ubuntu-18-04/
Submission: On September 06 via api from SG

Form analysis 1 forms found in the DOM

Name: mc-embedded-subscribe-formPOST https://linuxize.us17.list-manage.com/subscribe/post?u=35cd4cd9d021c25c3dd7cabfd&id=9cfa4c89de

<form action="https://linuxize.us17.list-manage.com/subscribe/post?u=35cd4cd9d021c25c3dd7cabfd&amp;id=9cfa4c89de" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="pt-8" novalidate="">
  <div class="flex flex-col sm:flex-row items-center justify-between w-full max-w-sm mx-auto mb-2"><input type="email" name="EMAIL" placeholder="Your email..." aria-label="email"
      class="appearance-none block w-full bg-white text-gray-800 border hover:border-gray-700 rounded py-3 px-4 mb-3 sm:mb-0">
    <input type="text" name="b_35cd4cd9d021c25c3dd7cabfd_9cfa4c89de" tabindex="-1" class="hidden">
    <button type="submit" name="subscribe" class="bg-indigo-700 tracking-wide hover:bg-indigo-800 text-white py-3 px-4 sm:ml-4 w-full sm:w-auto rounded">
      <span class="text-center">Subscribe</span></button>
  </div>
  <p class="w-full max-w-sm mx-auto my-0 text-sm">We’ll never share your email address or spam you.</p>
</form>

Text Content

Linuxize
Ubuntu Centos Debian Commands Series Donate



HOW TO INSTALL JAVA ON UBUNTU 18.04

Updated  Feb 24, 2020

•

5 min read

Contents

 * Prerequisites
 * Java variations
 * Installing the Default OpenJDK (Java 11)
 * Installing OpenJDK 8
 * Installing Oracle Java
 * Set the Default Java Version
 * Set the JAVA_HOME Environment Variable
 * Uninstall Java
 * Conclusion

Share:




Java is one of the most popular programming languages in the world, used for
building different types of cross-platform applications.

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.


PREREQUISITES #

Before continuing with this tutorial, make sure you are logged in as a user with
sudo privileges .


JAVA VARIATIONS #

Java is distributed in three different editions, Standard Edition (SE),
Enterprise Edition (EE), and Micro Edition (ME). This tutorial covers the
installation of the Java SE (Standard Edition) edition.

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.


We 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.


INSTALLING THE DEFAULT OPENJDK (JAVA 11) #

At the time of writing, the latest LTS version of Java is version 11.

Follow the steps below to install Java OpenJDK 11 on your Ubuntu system:

 1. First, update the apt package index with:
    
    sudo apt update

 2. Once the package index is updated install the default Java OpenJDK package
    with:
    
    sudo apt install default-jdk

 3. Verify the installation, by running the following command which will print
    the Java version:
    
    java -version
    
    The output will look something like this:
    
    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)

That’s it! At this point, you should have successfully installed Java on your
Ubuntu system.

JRE is included in the JDK package. If you need only JRE, install the
default-jre package:


INSTALLING OPENJDK 8 #

Java 8 is still the most widely-used version of Java. If your application
requires Java 8, you can install it by typing the following commands:


sudo apt updatesudo apt install openjdk-8-jdk


INSTALLING ORACLE JAVA #

Before installing Oracle Java, make sure you read the Oracle JDK License . The
license permits only non-commercial use of the software, such as personal use
and development use.

Oracle Java 11 can be installed from the Linux Uprising PPA.

The following steps describe how to install Oracle Java 11 on Ubuntu 18.04:

 1. Install the dependencies necessary to add a new repository :
    
    sudo apt install software-properties-common

 2. Enable the Linux Uprising PPA by running the following commands:
    
    sudo add-apt-repository ppa:linuxuprising/java

 3. Once the repository is added, update the packages list and install the
    oracle-java11-installer package by typing:
    
    sudo apt updatesudo apt install oracle-java11-installer
    
    You will be prompted to accept the Oracle license.

 4. Verify the installation by running the following command which will print
    the R version:
    
    java -version
    
    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)


SET THE DEFAULT JAVA VERSION #

To check the default Java version you would use the following command:


java -version

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)


If you have multiple Java installations to change the default version, use the
update-alternatives tool as shown below:

sudo update-alternatives --config java

There are 3 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 <enter> to keep the current choice[*], or type selection number:


To change the default Java version just enter the version number (the number in
the Selection column) and press Enter.


SET THE JAVA_HOME ENVIRONMENT VARIABLE #

Some applications written in Java are using the JAVA_HOME environment variable
to determine the Java installation location.

To set the JAVA_HOME environment variable, first, you need to find out the Java
installation paths using the update-alternatives command

sudo update-alternatives --config java

In our case, the installation paths are as follows:


 * OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java
 * OpenJDK 8 is located at /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

Copy the installation path of your preferred installation. Next, open the
/etc/environment file:


sudo nano /etc/environment

Add the following line, at the end of the file:

/etc/environment

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


Make sure you replace the path with the path to your preferred Java version.

You can either log out and log in or run the following source command to apply
the changes to your current session:

source /etc/environment

To verify that the JAVA_HOME environment variable is correctly set, run the
following echo command :


echo $JAVA_HOME

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


/etc/environment is a system-wide configuration file, which is used by all
users. If you want to set the JAVA_HOME variable on a per-user basis, add the
line to the .bashrc or any other configuration file which is loaded when the
user logs in.


UNINSTALL JAVA #

If for any reason you want to uninstall the Java package, you can uninstall it
like any other package installed with apt .

For example, if you want to uninstall the openjdk-8-jdk package run:

sudo apt remove openjdk-8-jdk


CONCLUSION #

In this tutorial, you learned how to install and manage multiple Java versions
on your Ubuntu server.

You can now install applications that run on Java, such as Tomcat ,
JBoss/WildFly , Apache Maven , Glassfish, Elasticsearch , Cassandra , Jenkins ,
Gradle …etc

If you have any questions or feedback, feel free to leave a comment.


java ubuntu

Not using Ubuntu 18.04?
Choose different OS:
centos 7
centos 8
debian 10
debian 9
ubuntu 20.04

Related Tutorials

 * How to Install Minecraft Server on Ubuntu 18.04
 * How to Install Gradle on Ubuntu 18.04
 * How to Install Apache Maven on Ubuntu 18.04
 * How to Install Tomcat 9 on Ubuntu 18.04
 * How to Install Eclipse IDE on Ubuntu 18.04
 * How to Install Tomcat 8.5 on Ubuntu 18.04
 * How to Install Apache Cassandra on Ubuntu 20.04




If you like our content, please consider buying us a coffee.
Thank you for your support!

Buy me a coffee

Sign up to our newsletter and get our latest tutorials and news straight to your
mailbox.

Subscribe

We’ll never share your email address or spam you.


RELATED ARTICLES

Dec 27, 2018


HOW TO INSTALL MINECRAFT SERVER ON UBUNTU 18.04



Oct 27, 2018


HOW TO INSTALL GRADLE ON UBUNTU 18.04



Oct 21, 2018


HOW TO INSTALL APACHE MAVEN ON UBUNTU 18.04


Write a comment

Please enable JavaScript to view the comments powered by Disqus.
ESC

© 2021 Linuxize.com Privacy Policy Terms Contact Advertise on Linuxize

ENFRDEESITHRSVSRSLNL


THIS WEBSITE USES COOKIES

This website use cookies to personalize content, provide custom experiences,
target ads, to provide social media features and to analyse our traffic. We also
share information about your use of our site with our social media, advertising
and analytics partners who may combine it with other information that you've
provided to them or that they've collected from your use of their services.
Below you have the option of selecting which types of cookies you'll allow to
store your personal information. To view the vendor list or change consent
settings at any time please visit our privacy policy using the link below.

Continue with Recommended Cookies

Vendor List | Cookie Details | Privacy Policy