• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Java on Debian 9 System

Written by Admin, Updated On May 20, 2019
debian, java
How to Install Java on Debian 9

Java is one of the most popular programming language. It is owned by Oracle and used to build different kinds of applications. We will install various versions of the Java Runtime Environment (JRE) and the Java Developer Kit (JDK). Also, we will install OpenJDK from official packages from Oracle. In this tutorial, you will learn how to install Java on Debian 9 system.

Prerequisites#

You should logged in on Debian 9 server using non-root user account with sudo privileges.

Install Default OpenJDK#

Java installation process is easy and straight forward. OpenJDK 8 JDK is available to install from the standard Debian repositories. Run the below command to install:

First update the package manager index using below command:

sudo apt update

Now install Java by typing following command:

sudo apt install default-jdk

Once the installation is finished you can confirm installation by checking version of jdk by:

java -version

It will show below output:

Output
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)

All done! Java is installed on you Debian system.

Install Specific Version of OpenJDK#

Currently, latest stable version is OpenJDK 11. This version is available from the Debian Backports repository.

So first we need to add Backports to your system software repository:

echo 'deb http://ftp.debian.org/debian stretch-backports main' | sudo tee /etc/apt/sources.list.d/stretch-backports.list

Once it is enabled you need to update package manager and then go ahead for install.

sudo apt update

You can install OpenJDK with your specified version. You just have to add version as per below syntax.

sudo apt install openjdk-[VERSION]-jdk

For example, latest stable version is OpenJDK 11. So we can install it using below command:

sudo apt install openjdk-11-jdk

Installing Java From Oracle#

Oracle provides license permits only non-commercial use, for personal use and development use only. So before going to install it read the Oracle JDK License. Here we are going to install Java 11.

Follow the below steps to install Java from Oracle:

At first, we install the necessary packages using below command:

sudo apt install dirmngr gnupg

Now you need to enable repositories after importing the PPA public key by following commands:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A

echo ‘deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main’ | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list

Once the repository is added and enabled, update the packages list index:

sudo apt update

Next, run the below command to install package:

sudo apt install oracle-java11-installer

You will be prompted to accept and agree for the Oracle license. Accept it to continue installation.

Check the installed version by running the following command:

java -version

It will show you output as below:

Output
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)

Setting up default Java Version#

If your Debian system have multiple version of Java then you can set default version as per your choice.

First, check the current default version by typing:

java -version

To change the default version use the update-alternatives system command as below:

sudo update-alternatives --config java
Output
There are 2 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 to keep the current choice[*], or type selection number:

You can see list of all installed Java versions. Select appropriate selection number to set as default version.

Uninstall Java#

You can uninstall the Java package same as other packages. For example, if you want to uninstall the default-jdk package simply run:

sudo apt remove default-jdk

Conclusion#

You have learned How to install and manage multiple Java versions on Debian 9 system. At the end you also learned how to set default Java version.

If you have any queries regarding this tutorial feel free to comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article Most Used Nginx Commands in Linux System
Next Article   How to Check CentOS Version With Different Methods

Related Posts

  • How to Install WordPress with Nginx on Debian 11

    How to Install WordPress with Nginx on Debian 11

    March 22, 2023
  • How to Install and Use Docker on Debian 11

    How to Install and Use Docker on Debian 11

    March 10, 2023
  • How to Install MariaDB on Debian 11 Bullseye

    How to Install MariaDB on Debian 11 Bullseye

    March 8, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook