Java is a popular programming language for the system software development and web application. You need to install the Java Development Kit (JDK) and Java Runtime Environment (JRE) for the setup of the Java development environment. JDK compiled the source java file and make a java class file. JRE is used to run that intermediate class file. This tutorial will guide you to install Oracle Java 11 LTS version on Debian 9 Stretch Linux system.
Step 1 – Prerequsities
Before beginning the installation login to shell as the sudo user and install some required packages on your Debian system.
sudo -i apt install wget libasound2 libasound2-data
Step 2 – Download Debian Package
Download the latest Java SE Development Kit 11 LTS debian file release from its official download page or use following commands to download from command line.
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" \ http://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.deb
Step 3 – Install Java 11 on Debian 9
Use default Debian package installer (dpkg) to install downloaded Java on your system. Simply run the following command on command prompt.
dpkg -i jdk-11.0.1_linux-x64_bin.deb
Then configure Java 11 as the default version on your system.
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 2 update-alternatives --config java
According to the above screenshot, there are 3 versions installed. Java 11 is listed on slection number 2, So entered 2 and press Enter. Now Java 11 is installed as default Java version on my Debian 9 system.
There are some other binaries to set as default for JDK installation. Execute the commands to set javac and jar as default:
update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-11.0.1/bin/jar 2 update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.1/bin/javac 2 update-alternatives --set jar /usr/lib/jvm/jdk-11.0.1/bin/jar update-alternatives --set javac /usr/lib/jvm/jdk-11.0.1/bin/javac
Step 4 – Verify Java Version
After the installation process checks the currently active Java version on your Debian system by running the following command.
java -version java version "11.0.1" 2018-10-16 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
Step 5 – Configure Environment Variables
Most of the Java-based applications uses environment variables to work. Create a script as below. Now set all the required environment variables for Java. This file will automatically reload settings on system reboot.
sudo nano /etc/profile.d/jdk.sh
Add/Update following values:
export J2SDKDIR=/usr/lib/jvm/jdk-11.0.1 export J2REDIR=/usr/lib/jvm/jdk-11.0.1 export PATH=$PATH:/usr/lib/jvm/jdk-11.0.1/bin:/usr/lib/jvm/jdk-11.0.1/db/bin export JAVA_HOME=/usr/lib/jvm/jdk-11.0.1 export DERBY_HOME=/usr/lib/jvm/jdk-11.0.1/db
Save your file and exit. Now load these setting to current active shell also
You have successfully installed Java 11.0.1 on Debian 9 Stretch Linux system.