How to Install Java on Ubuntu 19.10 Complete Guide for Beginners all steps

Vijay Kumar
4 min readJan 21, 2020

Some programs/tools/utility on Ubuntu required java/JVM, without java these programs are not working. Are you facing the same problem? Don’t worry!

Today I am going to cover in this article how to install Java on Ubuntu. This article will cover the complete tutorial step by step.

You can get java on Ubuntu via three packages JRE, OpenJDK and Oracle JDK.

Java and Java’s Virtual Machine (JVM) are widely used and required to run much software.

Check if java is already installed on Ubuntu

It is necessary to check if java is already installed, so run the following command and check it.

If the java is not installed on your system you will get the following result, and if java installed you will get some different output.

Prerequisites to install java on Ubuntu

What is the requirements to install java on Ubuntu, Of course, you should know otherwise you will get the error or face the problems?

If you know the prerequisites, you can install any software without any problem. The following are prerequisites for installing java.

  • You have installed Ubuntu (It should not be live boot).
  • Login user must be Sudo/root user
  • Active internet connection on System.

Install Default JRE/JDK

apt-get is a utility used to install, update, remove packages on Ubuntu. This is the easiest way to install java on Ubuntu, open terminal run command, sit back on the chair, have a coffee, and java or other packages will be install automatically.

Before going to install java on Ubuntu you must update the packages list used by apt-get utility.

To update package list use following command

$sudo apt-get update

Next step to install default-jre after completing package list updation.

$sudo apt-get install default-jre

Next step install default JDK or OpenJDK on the system.

The JDK is usually only needed if you are going to compile Java programs or if the software that will use Java specifically requires it.

The JDK does contain the JRE, so there are no disadvantages if you install the JDK instead of the JRE, except for the larger file size.

Go through the following command to install JDK

$sudo apt-get install default-jdk

vijay@Ubuntu-19:~ $sudo apt-get install default-jdk Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: default-jdk-headless libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev Suggested packages: libice-doc libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-11-demo openjdk-11-source visualvm The following NEW packages will be installed: default-jdk default-jdk-headless libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-dev openjdk-11-jdk openjdk-11-jdk-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev 0 upgraded, 16 newly installed, 0 to remove and 8 not upgraded. Need to get 210 MB of archives. After this operation, 226 MB of additional disk space will be used. Do you want to continue? [Y/n]

Install the Oracle JDK on Ubuntu

To install Oracle JDK java version 11 and 12, you must add a new repository by using the following command

$sudo add-apt-repository ppa:linuxuprising/java

vijay@Ubuntu-19:~ $vijay@Ubuntu-19:~$ sudo add-apt-repository ppa:linuxuprising/java

When you make entry of the repository server in the repository list, you must update again repository list.

Now use following command to install oracle JDK 12 on Ubuntu 19.04 Server, using following command

$sudo apt install oracle-java12-installer

Managing java on Ubuntu

You have installed java on your system, later newer version of java will launched. Now you think to install new version. No, problem at all, you can install new version.

But if you want your system use newer java version, you will have to configure. Following command is useful

$sudo update-alternatives -config java

You will see all installed package on your system, select number and hit enter.

$sudo update-alternatives --config java [sudo] password for vijay: 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-12-oracle/bin/java 1091 manual mode Pressvijay@Ubuntu-19:~  to keep the current choice[*], or type selection number: vijay@Ubuntu-19:~ $

Uninstall Oracle Java12

To remove oracle java12, run command to remove the installer script. You can use apt-get remove to uninstall program from the Ubuntu 19.04 desktop/server.

Conclusion

By now you have learnt how to install java on ubuntu. Now you can install default jre and jdk, and oracle java. Also you can install multiple version of java.

So If you have any question, write in commentbox now. you can write me vijay@cyberpratibha.com

Cheers!

Originally published at https://www.cyberpratibha.com on January 21, 2020.

--

--