How To Install Java with `apt` on Ubuntu 18.04


Java and the JVM (Java’s virtual machine) are required for many kinds of software, including Tomcat, Jetty, Glassfish, Cassandra and Jenkins.

In this guide, you will install various versions of the Java Runtime Environment (JRE) and the Java Developer Kit (JDK) using apt . You’ll install OpenJDK as well as official packages from Oracle. You’ll then select the version you wish to use for your projects. When you’re finished, you’ll be able to use the JDK to develop software or use the Java Runtime to run software.


To follow this tutorial, you will need:

Installing the Default JRE/JDK

The easiest option for installing Java is to use the version packaged with Ubuntu. By default, Ubuntu 18.04 includes Open JDK, which is an open-source variant of the JRE and JDK.

This package will install either OpenJDK 10 or 11.

  • Prior to September 2018, this will install OpenJDK 10.
  • After September 2018, this will install OpenJDK 11.

To install this version, first update the package index:

  • sudo apt update

Next, check if Java is already installed:

  • java -version

If Java is not currently installed, you’ll see the following output:

Command 'java' not found, but can be installed with:

apt install default-jre
apt install openjdk-11-jre-headless
apt install openjdk-8-jre-headless
apt install openjdk-9-jre-headless

Execute the following command to install OpenJDK:

  • sudo apt install default-jre

This command will install the Java Runtime Environment (JRE). This will allow you to run almost all Java software.

Verify the installation with:

  • java -version

You’ll see the following output:

openjdk version "10.0.1" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 10.0.1+10-Ubuntu-3ubuntu1, mixed mode)

You may need the Java Development Kit (JDK) in addition to the JRE in order to compile and run some specific Java-based software. To install the JDK, execute the following command, which will also install the JRE:

  • sudo apt install default-jdk

Verify that the JDK is installed by checking the version of javac, the Java compiler:

  • javac -version

You’ll see the following output:

javac 10.0.1

Next, let’s look at specifying which OpenJDK version we want to install.

Installing Specific Versions of OpenJDK

While you can install the default OpenJDK package, you can also install different versions of OpenJDK.

OpenJDK 8

Java 8 is the current Long Term Support version and is still widely supported, though public maintenance ends in January 2019. To install OpenJDK 8, execute the following command:

  • sudo apt install openjdk-8-jdk

Verify that this is installed with

  • java -version

You’ll see output like this:

openjdk version "1.8.0_162"
OpenJDK Runtime Environment (build 1.8.0_162-8u162-b12-1-b12)
OpenJDK 64-Bit Server VM (build 25.162-b12, mixed mode)

It is also possible to install only the JRE, which you can do by executing sudo apt install openjdk-8-jre.

OpenJDK 10/11

Ubuntu’s repositories contain a package that will install either Java 10 or 11. Prior to September 2018, this package will install OpenJDK 10. Once Java 11 is released, this package will install Java 11.

To install OpenJDK 10/11, execute the following command:

  • sudo apt install openjdk-11-jdk

To install the JRE only, use the following command:

  • sudo apt install openjdk-11-jre

Next, let’s look at how to install Oracle’s official JDK and JRE.

Installing the Oracle JDK

If you want to install the Oracle JDK, which is the official version distributed by Oracle, you’ll need to add a new package repository for the version you’d like to use.

To install Java 8, which is the latest LTS version, first add its package repository:

  • sudo add-apt-repository ppa:webupd8team/java

When you add the repository, you’ll see a message like this:

 Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK8). There are no actual Jav
a files in this PPA.

Important -> Why Oracle Java 7 And 6 Installers No Longer Work:

Update: Oracle Java 9 has reached end of life:

The PPA supports Ubuntu 18.04, 17.10, 16.04, 14.04 and 12.04.

More info (and Ubuntu installation instructions):
- for Oracle Java 8:

Debian installation instructions:
- Oracle Java 8:

For Oracle Java 10, see a different PPA:

More info:
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Press ENTER to continue. Then update your package list:

  • sudo apt update

Once the package list updates, install Java 8:

  • sudo apt install oracle-java8-installer

Your system will download the JDK from Oracle and ask you to accept the license agreement. Accept the agreement and the JDK will install.

Now let’s look at how to select which version of Java you want to use.

Managing Java

You can have multiple Java installations on one server. You can configure which version is the default for use on the command line by using the update-alternatives command.

  • sudo update-alternatives –config java

This is what the output would look like if you’ve installed all versions of Java in this tutorial:

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      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1081      manual mode

Choose the number associated with the Java version to use it as the default, or press ENTER to leave the current settings in place.

You can do this for other Java commands, such as the compiler (javac):

  • sudo update-alternatives –config javac

Other commands for which this command can be run include, but are not limited to: keytool, javadoc and jarsigner.

Setting the JAVA_HOME Environment Variable

Many programs written using Java use the JAVA_HOME environment variable to determine the Java installation location.

To set this environment variable, first determine where Java is installed. Use the update-alternatives command:

  • sudo update-alternatives –config java

This command shows each installation of Java along with its installation path:

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      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1081      manual mode

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

In this case the installation paths are as follows:

  1. OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
  2. OpenJDK 8 is located at /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java.
  3. Oracle Java 8 is located at /usr/lib/jvm/java-8-oracle/jre/bin/java.

Copy the path from your preferred installation. Then open /etc/environment using nano or your favorite text editor:

  • sudo nano /etc/environment

At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path:


Modifying this file will set the JAVA_HOME path for all users on your system.

Save the file and exit the editor.

Now reload this file to apply the changes to your current session:

  • source /etc/environment

Verify that the environment variable is set:

  • echo $JAVA_HOME

You’ll see the path you just set:


Other users will need to execute the command source /etc/environment or log out and log back in to apply this setting.


In this tutorial you installed multiple versions of Java and learned how to manage them. You can now install software which runs on Java, such as Tomcat, Jetty, Glassfish, Cassandra or Jenkins.


How to Install Grub Customizer in Ubuntu 18.04 LTS

For those who need to modify the default Grub boot-loader settings, Grub Customizer is a useful tool with a graphical user interface.

With grub customizer, you can:

  • Rearrange, add, remove, rename boot menu entries.
  • Hide or show boot menu while starting up.
  • Change the default boot entry.
  • Edit kernel parameters.
  • Change the time delay to boot the default entry.
  • Change text colors and screen background image.
  • Reinstall Grub boot-loader into Windows MBR.


To install Grub Customizer in Ubuntu:

The software has an official PPA repository contains the packages for all current Ubuntu releases.

1. Open terminal either via Ctrl+Alt+T or by searching for ‘terminal’ from app launcher. When it opens, run command to add the PPA:

sudo add-apt-repository ppa:danielrichter2007/grub-customizer

Input your password (no visual feedback while typing) when it prompts and hit Enter to continue.


2. After added the PPA, run commands one by one to refresh package cache and install Grub Customizer:

sudo apt-get update

sudo apt-get install grub-customizer

Once installed, launch the software from your application launcher and enjoy!


To remove the software, run command in terminal:

sudo apt-get remove --autoremove grub-customizer

And you can remove PPAs via Software & Updates utility under ‘Other Software’ tab.


/* */

Windows 10 deleted GRUB [FIXED BY EXPERTS]

To fix various PC problems, we recommend this tool: This software will repair common computer errors, protect you from file loss, malware, hardware failure and optimize your PC for maximum performance. Fix PC issues and remove viruses now in 3 easy steps:
  1. Download this PC Repair Tool rated Great on
  2. Click Start Scan to find Windows issues that could be causing PC problems.
  3. Click Repair All to fix issues with Patented Technologies (Exclusive Discount for our readers).
GRUB is a multiboot loader and an essential part of the Linux operating system, but some users on the Microsoft community and Linux forums have reported that Windows 10 has deleted their grub, thus leaving their Linux distribution unable to boot. If you are also troubled this issue, here are a couple of solutions that can help you resolve this problem.

How do I recover GRUB after installing Windows?

1. Run Boot Repair

Boot Repair Disk to install GRUB windows 10 deleted grub
  1. There are two ways to get boot-repair. First is to create a disk containing the tool like Boot-Repair-Disk. This will help you to create a disk starting Boot-Repair automatically and boot on it.
  2. The second option is to Install Boot-Repair in Ubuntu. To do this, create Ubuntu Live-session on your USB and then choose “Try Ubuntu“.
  3. Connect to the Internet.
  4. Open a new terminal, and type the following command. Press enter after running each command. sudo add-apt-repository ppa:yannubuntu/boot-repair sudo apt-get update sudo apt-get install -y boot-repair && boot-repair
  5. Now you need to launch Boot-Repair by typing boot-repair in a terminal.  You can also launch it from the Dash (Ubuntu logo at the top).
  6. Next, click the “Recommended Repair” button.
  7. Wait for the repair to finish. Note the URL that appeared on the screen.
  8. Now reboot the system and check if you can access the OS and GRUB is reinstalled.

Want to learn how to dual boot Windows 10? You won’t believe how easy it is!

2. Reinstall GRUB

grub menu windows 10 deleted grub
  1. First, boot into your system using any Live Linux Distribution.
  2. Open Gnome Disks or GParted, the partition editor.
  3. Now find the partition where your Linux system is on. The Linux system is usually in /dev/sdax path (here X means number).
  4. Now close the Disk partition tool that is running (Gnome Disks or GParted).
  5. Open a terminal and run the following command and press Enter to execute it. sudo mount /dev/sdaX /mnt && sudo mount –bind /dev /mnt/dev && sudo mount –bind /dev/pts /mnt/dev/pts && sudo mount –bind /proc /mnt/proc && sudo mount –bind /sys /mnt/sys && sudo chroot /mnt
  6. In the above command replace X with the disk number that you discovered in the step 3.
  7. Next, enter the following command and hit enter as well. grub-install /dev/sda && update-grub && exit udo umount /mnt/sys && sudo umount /mnt/proc && sudo umount /mnt/dev/pts && sudo umount /mnt/dev && sudo umount /mnt && reboot
  8. If everything goes right, this should reinstall GRUB. Reboot the computer and check if GRUB is re-installed successfully
By following any one of the methods above you should be able to fix the deleted GRUB issue. One thing to keep in mind is that if you want to dual boot on your system with Linux and Windows 10, always install Windows 10 first and then install Linux. This way Windows 10 won’t delete the GRUB by mistaking the EFI partition for its own.