,

How to install Java JDK on ubuntu Debian/Linux 11

Posted by

Java Development Kit (JDK) is a software development kit that is used to develop applications in the Java programming language. The Java applications include desktop servers, mobile devices, and embedded systems

Java JDK can be installed in various operating systems which include windows, Linux, and macOS, To develop java applications we use IDEs such as Eclipse, IntelliJ IDEA, NetBeans, and many others

Steps to install Java JDK on Ubuntu

The first step is to update the package list to the latest version using the command below

sudo apt update

to install the latest package of JDK we use the command below

sudo apt install default-jdk

The command above will install the latest OpenJDK available in the Debian package, we can confirm the installed package using the command below as well as verify the installation if successful

java -version
Java installation successful

How to Install Specific version of JDK on Ubuntu Debian

first is to download the JDK Package we wish to install using the following command, we are installing JDK version 11.0.2 a 64-bit version, in case you are installing a different version,I will advise you to get the download URL from the Oracle website.

wget https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz

After successfully downloading the package we now extract the downloaded files using the commands below

tar -xzf openjdk-11.0.2_linux-x64_bin.tar.gz

Once extracted we run the following commands to create a folder and copy the JDK files to the folder created, Below are the commands

sudo mkdir -p /usr/lib/jvm

sudo mv jdk-11.0.2 /usr/lib/jvm

What follows next is to set the JDK environment variable, We will use the commands below

export JAVA_HOME=/usr/lib/jvm/jdk-11.0.2
export PATH=$PATH:$JAVA_HOME/bin

once the environment is settled up you can verify the installation using the command below

java -version

Setting JDk Default for the System

This will be achieved using the command listed below, for our case we have 2 java files installed, one is from Debian packages and the other is the one we installed manually, below command show us how to make one the default for our system.

//Register the new version of java we just installed

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.2 /bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.2 /bin/javac 1

//set default version

sudo update-alternatives --config java
sudo update-alternatives --config javac

Leave a Reply

Your email address will not be published. Required fields are marked *