본문 바로가기
OS/Linux

How to Install Java on Linux Mint 19

by 신군. 2020. 1. 11.
반응형

 

 

 

 

 

How to Install Java on Linux Mint 19

Table of Contents

Install Java on Linux Mint 19

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

Java has the following three editions:

  1. Standard Edition(SE).
  2. Micro Edition(ME).
  3. Enterprize Edition(EE).

Following two implementations available for Java:

  1. Oracle Java.
  2. OpenJDK Java.

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

Prerequisites

Before you start to install 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 the default version for Linux Mint 19. To install OpenJDK 10 run following commands.

Update the package manager index typing following command.

sudo apt updateCopy

Enter the following command to install Default OpenJDK on Linux Mint 19.

 

sudo apt install default-jdkCopy

Confirm the installation and check the version typing following command.

java -versionCopy

The output should be:

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

2. Install OpenJDK 8, 10, or 11

You can install the specific version of OpenJDK by using the following command. Replacing [VERSION_NUMBER] with the version number you want to install.

sudo apt install openjdk-[VERSION_NUMBER]-jdkCopy

For example, if you want to install OpenJDK 8 which is the current LTS version of OpenJDK then just run following command.

sudo apt install openjdk-8-jdkCopy

3. Install Oracle Java With apt

Oracle Java which is the official version from Oracle can be installed from the webupd8team repository. You will need to add the webupd8team repository to the sources list running following command.

sudo add-apt-repository ppa:webupd8team/javaCopy

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

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

You will be prompted to accept license terms select YES to continue.

install java on Linux Mint 19 – accept terms

After accepting the license it will 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 want to install Java 10 then download the package from Oracle Official Website. Here we are going to install Java 10 while you can 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.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.tar.gzCopy

Create a new directory for java installation.

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

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-10Copy

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" 1500Copysudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/oracle-java-10/jdk-10.0.2/bin/javac" 1500Copysudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/oracle-java-10/jdk-10.0.2/bin/javaws" 1500Copy

5. Setting up default Java Version on Linux Mint 19

If you have installed multiple versions of Java on your system then you can change the default version running following command.

Check Current Java Version running following command.

java -versionCopy

Now to change the default Java version run the following command.

sudo update-alternatives --config javaCopy

The output should be:

There is 1 choice for the alternative 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: Copy

NOTE: to change the version just enter the number in the selection column

Another example:

install java – set default java version

6. Set the JAVA_HOME Environment Variable

To set the JAVA_HOME environment variable run following command and copy the path you want to be set as JAVA_HOME.

sudo update-alternatives --config javaCopy

Run the following command to set the JAVA_HOME variable.

sudo nano /etc/environmentCopy

Add the following line to the end of file

JAVA_HOME="THE PATH YOU HAVE COPIED"Copy

Exit by using Ctrl+x then pressing y:

install java – edit environment file

Apply the changes by running the following command.

source /etc/environmentCopy

Now verify JAVA_HOME path typing:

echo $JAVA_HOMECopy

install java – echo JAVA HOME path

Conclusion

You have successfully learned how to install Java on Linux Mint 19. If you have any queries regarding this then please don’t forget to comment below.

반응형