YouTube Icon

Code Playground.

How to Install Java on Ubuntu 18.04

CFG

How to Install Java on Ubuntu 18.04

Java is quite possibly the most well known programming dialects on the planet, utilized for building various sorts of cross-stage applications. 

This instructional exercise depicts how to introduce different renditions of OpenJDK just as Oracle Java on Ubuntu 18.04. Similar guidelines apply for Ubuntu 16.04 and any Ubuntu-based dissemination, including Kubuntu, Linux Mint and Elementary OS. 

Prerequisites

Prior to proceeding with this instructional exercise, ensure you are signed in as a client with sudo advantages . 

Java variations

Java is disseminated in three distinct versions, Standard Edition (SE), Enterprise Edition (EE), and Micro Edition (ME). This instructional exercise covers the establishment of the Java SE (Standard Edition) version. 

OpenJDK and Oracle Java are the two primary executions of Java, with practically no contrasts between them aside from that Oracle Java has a couple of extra business highlights. 

There are two diverse Java bundles in Ubuntu stores, Java Runtime Environment (JRE), and the Java Development Kit (JDK). 

On the off chance that you just need to run Java programs, at that point you need JRE, which contains just the Java Runtime Environment. Java engineer ought to introduce JDK, which likewise incorporates the turn of events/troubleshooting devices and libraries. 

We will tell you the best way to introduce different Java bundles. On the off chance that you don't know which Java usage or rendition to utilize, the overall suggestion is to stay with the default OpenJDK form accessible on Ubuntu 18.04. 

Installing the Default OpenJDK (Java 11)

At the hour of composing, the most recent LTS form of Java is variant 11. 

Follow the means beneath to introduce Java OpenJDK 11 on your Ubuntu framework: 

To begin with, update the well-suited bundle list with: 

sudo apt update

When the bundle file is refreshed introduce the default Java OpenJDK bundle with: 

sudo apt install default-jdk

Check the establishment, by running the accompanying order which will print the Java rendition: 

java -version

The yield will look something like this: 

openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)

That is it! Now, you ought to have effectively introduced Java on your Ubuntu framework. 

JRE is remembered for the JDK bundle. In the event that you need just JRE, introduce the default-jre bundle: 

Installing OpenJDK 8

Java 8 is as yet the most generally utilized adaptation of Java. On the off chance that your application requires Java 8, you can introduce it by composing the accompanying orders: 

sudo apt update
sudo apt install openjdk-8-jdk

Installing Oracle Java

Prior to introducing Oracle Java, ensure you read the Oracle JDK License . The permit allows just non-business utilization of the product, for example, individual use and advancement use. 

Prophet Java 11 can be introduced from the Linux Uprising PPA. 

The accompanying advances portray how to introduce Oracle Java 11 on Ubuntu 18.04: 

Introduce the conditions important to add another store : 

sudo apt install software-properties-common

Empower the Linux Uprising PPA by running the accompanying orders: 

sudo add-apt-repository ppa:linuxuprising/java

When the store is added, update the bundles list and introduce the prophet java11-installer bundle by composing: 

sudo apt update
sudo apt install oracle-java11-installer

You will be incited to acknowledge the Oracle permit. 

Confirm the establishment by running the accompanying order which will print the R adaptation: 

java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

Set the Default Java Version

To check the default Java variant you would utilize the accompanying order: 

java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)

On the off chance that you have various Java establishments to change the default adaptation, utilize the update-options instrument as demonstrated as follows: 

sudo update-alternatives --config java
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      1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

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

To change the default Java form simply enter the variant number (the number in the Selection segment) and press Enter. 

Set the JAVA_HOME Environment Variable

A few applications written in Java are utilizing the JAVA_HOME climate variable to decide the Java establishment area. 

To set the JAVA_HOME climate variable, first, you need to discover the Java establishment ways utilizing the update-choices order 

sudo update-alternatives --config java

For our situation, the establishment ways are as per the following: 

OpenJDK 11 is situated at/usr/lib/jvm/java-11-openjdk-amd64/canister/java 

OpenJDK 8 is situated at/usr/lib/jvm/java-8-openjdk-amd64/jre/canister/java 

Duplicate the establishment way of your favored establishment. Next, open the/and so on/climate record: 

sudo nano /etc/environment

Add the accompanying line, toward the finish of the document: 

/etc/environment

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Ensure you supplant the way with the way to your favored Java adaptation. 

You can either log out and sign in or run the accompanying source order to apply the progressions to your present meeting: 

source /etc/environment

To confirm that the JAVA_HOME climate variable is effectively set, run the accompanying reverberation order : 

echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64

/and so on/climate is a framework wide setup record, which is utilized by all clients. In the event that you need to set the JAVA_HOME variable on a for every client premise, add the line to the .bashrc or some other arrangement document which is stacked when the client signs in. 

Uninstall Java

In the event that in any way, shape or form you need to uninstall the Java bundle, you can uninstall it like some other bundle introduced with well-suited . 

For instance, on the off chance that you need to uninstall the openjdk-8-jdk bundle run: 

sudo apt remove openjdk-8-jdk

Conclusion

In this instructional exercise, you figured out how to introduce and deal with different Java variants on your Ubuntu worker. 

You would now be able to introduce applications that sudden spike in demand for Java, for example, Tomcat , JBoss/WildFly , Apache Maven , Glassfish, Elasticsearch , Cassandra , Jenkins , Gradle … and so forth 

On the off chance that you have any inquiries or criticism, don't hesitate to leave a remark.




CFG