Install Java in all Linux Operating Systems, Ubuntu, Kali Linux, Linux Mint

Install Java on Linux Mint 19


Java is that the popular programing language owned by Oracle. Java is used to build cross-platform applications. Over 3 billion devices run on Java. In this tutorial, we are getting to install Java on Linux Mint 19 using different methods.

Java has the following three editions:

 Standard Edition(SE).
 Micro Edition(ME).
 Enterprize Edition(EE).

Following two implementations available for Java:

 Oracle Java.
 OpenJDK Java.

There is no more difference in Oracle Java and OpenJDK Java as Oracle Java provides some additional enterprise features.
Prerequisites

Before you begin to put in Java on Linux Mint 19. You must have the non-root user account on your system with sudo privileges.

1. Install Default OpenJDK


Currently, OpenJDK 10 is that the default version for Linux Mint 19. To install OpenJDK 10 run following commands.

Update the package manager index typing following command.

sudo apt update

Enter the subsequent command to put in Default OpenJDK on Linux Mint 19.

sudo apt install default-jdk

Confirm the installation and check the version typing following command.

java -version

The output should be:

openjdk version "10.0.1" 2018-05-29
OpenJDK Runtime Environment
OpenJDK 64-Bit Server VM

2. Install OpenJDK 8, 10, or 11


You can install the precise version of OpenJDK by using the subsequent command. Replacing [VERSION_NUMBER] with the version number you would like to put in .

sudo apt install openjdk-[VERSION_NUMBER]-jdk

For example, if you would like to put in OpenJDK 8 which is that the current LTS version of OpenJDK then just run following command.

sudo apt install openjdk-8-jdk

3. Install Oracle Java With apt

Oracle Java which is that the official version from Oracle are often installed from the webupd8team repository. You will got to add the webupd8team repository to the sources list running following command.

sudo add-apt-repository ppa:webupd8team/java

Now update the package manager index and install Oracle with the subsequent command.

sudo apt update && sudo apt-get install oracle-java8-installer

You will be prompted to simply accept license terms select YES to continue.
install java on ubuntu 18.04 - accept terms
install java on Linux Mint 19 – accept terms

After accepting the license it'll download Oracle JDK and install it on your system.

4. Install Java From Oracle Website on Linux Mint 19


As the web8team repository only contains Java 8. If you would like to put in Java 10 then download the package from Oracle Official Website. Here we are getting to install Java 10 while you'll choose another version.

Download Oracle Java 10 using the following command.

curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/10.0.210.0.2_linux-x64_bin.tar.gz

Create a new directory for java installation.

sudo mkdir /usr/local/oracle-java-10

Now extract downloaded Java file inside the recently created directory.

sudo tar -zxf jdk-10.0.2_linux-x64_bin.tar.gz -C /usr/local/oracle-java-10

Now run the following command to create alternatives. it will create symbolic links for default commands.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/oracle-java-10/jdk-10.0.2/bin/java" 1500

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/oracle-java-10/jdk-10.0.2/bin/javac" 1500

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/oracle-java-10/jdk-10.0.2/bin/javaws" 1500

5. fixing default Java Version on Linux Mint 19


If you've got installed multiple versions of Java on your system then you'll change the default version running following command.

Check Current Java Version running following command.

java -version

Now to vary the default Java version run the subsequent command.

sudo update-alternatives --config java

The output should be:

There is 1 choice for the choice java (providing /usr/bin/java).

 Selection Path Priority Status
---------------------------------------------------------------------------------------
 0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
* 2 /usr/local/oracle-java-10/jdk-10.0.2/bin/java 1500 manual mode

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

NOTE: to vary the version just enter the amount within the selection column

Another example:
install java - set default java version
install java – set default java version
6. Set the JAVA_HOME Environment Variable


To set the JAVA_HOME environment variable run following command and replica the trail you would like to be set as JAVA_HOME.

sudo update-alternatives --config java

Run the subsequent command to line the JAVA_HOME variable.

sudo nano /etc/environment

Add the subsequent line to the top of file

JAVA_HOME="THE PATH YOU HAVE COPIED"

Exit by using Ctrl+x then pressing y:
install java - edit envirnment file
install java – edit environment file


Apply the changes by running the following command.

source /etc/environment

Now verify JAVA_HOME path typing:

echo $JAVA_HOME

install java - echo JAVA HOME path
install java – echo JAVA HOME path

Comments