How to Install Java, JRE, JDK on Ubuntu, Linux Mint

2 min


A complete guide to install Java/JRE/JDK on Ubuntu including Ubuntu 16.04 LTS Xenial Xerus.

Many programs needs Java Runtime Environments (JRE) to run properly. In Ubuntu, to install Java there are lots of options available – openjre, defaultjre or oraclejre. This article describes how to install those and configure JAVA_HOME environment variable.

Install Default JRE/JDK

Unless your package requires specific Oracle Java, OpenJDK/JRE; you can go ahead with installing default JRE/JDK which would work in most of the cases.

  • Run below command to update the package index
sudo apt-get update
  • Check if Java is already installed in your system by running below command
java -version

If you don’t get a message with Java version, then Java is not installed in your system. You can proceed to install Java.

  • To install default Java Runtime Environment (JRE), run below command from terminal
sudo apt-get install default-jre
  • To install default Java Development Kit (JDK), run beow command from terminal
sudo apt-get install default-jdk

This is everything you need to have Java installed in your system. After installation you can run java -version to check whether Java is installed.

Installing OpenJDK 8

  • To install OpenJDK 8 run below commands.
  • for Java Runtime Environment
sudo apt-get install openjdk-8-jre
  • for Java Development Kit
sudo apt-get install openjdk-8-jdk

To Install Oracle JDK 8 via PPA

WebUpd8 team maintains a PPA for all Oracle Java versions. Run below command to add the PPA.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Run below commands to install Oracle Java 8 in Ubuntu, Linux Mit and derivatives

sudo apt-get install oracle-java8-installer

Setting up JAVA_HOME environment variable

  • Check the path where Java is installed. Run below command
sudo update-alternatives --config java
  • This would give a list of Java paths if you have multiple version of Java is installed in your system. If only one version is installed, then you would get a response like this:

Java Path Install

The Java is installed in path /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java.

  • Open /etc/environment file via administrator mode in your favorite text editor
sudo gedit /etc/environment
  • Add below line in the file and save the file.
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre"

Make sure to change the path according to your system.

  • Run below command to reload the file
source /etc/environment
  • Run below command to check if your Java installation setting of JAVA_HOME is correct.
echo $JAVA_HOME

Java Home Set

 

Questions, suggestions? Drop a comment using comment box below.

 


We bring the latest tech, software news and stuff that matters. Stay in touch via Telegram, Twitter, YouTube, and Facebook and never miss an update!

Join our Telegram channel and stay informed on the move.


Arindam

Creator of debugpoint.com. All time Linux user and open-source supporter. Connect with me via Telegram, Twitter, LinkedIn, or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
2
0
Would love your thoughts, please comment.x
()
x