In this session will discuss the remaining method to install java on ubuntu as a a continuation of the first blog.
How to install Java (the default JDK) on Ubuntu using apt-get
We’ll start with our instructions on how to install the latest recommended version of Java (JDK) using the Ubuntu package.
By installing the JDK (Java Development Kit), you’ll also install the JRE (Java Runtime Environment). OpenJDK, an open-source alternative to the Oracle Java development kit
To know more about Oracle JDk and Open JDK please go through https://www.openlogic.com/blog/java-experts-openjdk-vs-oracle-jdk
Before we begin installing Java:
Some things you’ll need before we start installing Java:
- An Ubuntu desktop/server
- A sudo/root user.If you’re using a non-root user then you’ll need to append ‘sudo’ to most commands.
- Make sure you don’t have Java already installed. If you do, remove it, or if you want to use multiple Java versions/installs, then keep it and configure them later
Step 1: Update Ubuntu
The first thing you should always do is update your system. You can do so by running the following command:
sudo apt-get update
Step 2: Install the default JDK
Run the following command:
sudo apt-get install default-jdk
This package will run an installer for The OpenJDK 8, which is the latest LTS version available for Ubuntu 16.04 release.
By default, Ubuntu 18.04 includes OpenJDK version 11, which is an open-source variant of the JRE and JDK
Verify that Java and the Java compiler have been properly installed:
java -version javac -version
sudo apt-get install openjdk-8-jre
Note that this is unnecessary if you’ve installed OpenJDK, since it includes the JRE.
Set Java Home Environment
Many applications include code or configuration that references the
JAVA_HOME environment variable. This variable points them to the Java binary file, allowing them to run Java code.
To see how to configure this please check my first blog regarding the installation of java from the link : How to install and configure java on ubuntu 16.04/18.04 LTS-PART 1
Verify the variable was set correctly:
This should return the path to the Java binary.
Now we have successfully installed and configured openjdk java in our system.