Java is a popular programming language for 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. This tutorial will guide you to install Oracle Java 11 LTS version on Debian 10 Stretch Linux system.
Step 1 – Prerequsities
First of all, Login to Debian 10 Buster system as the sudo user and install some required packages on your Debian system.
sudo -i apt install wget libasound2 libasound2-data
Step 2 – Download Java 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.2+9/f51449fcd52f4d52b93a989c5c56ed3c/jdk-11.0.2_linux-x64_bin.deb
Step 3 – Install Oracle Java on Debian 10
Now, use Debian package installer utility (dpkg) to install downloaded Java package on your system. Simply run the following command on system terminal.
dpkg -i jdk-11.0.2_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.2/bin/java 2 update-alternatives --config java
As per the below screenshot, there are 2 java versions installed. OpenJDK 11 is configured as default java version. Java 11 is listed on selection number 2, So entered 2 and press Enter. Now Oracle Java 11 is configured as default Java version.
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.2/bin/jar 2 update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.2/bin/javac 2 update-alternatives --set jar /usr/lib/jvm/jdk-11.0.2/bin/jar update-alternatives --set javac /usr/lib/jvm/jdk-11.0.2/bin/javac
Step 4 – Verify Java Version
Therefore Java 11 has successfully installed on your Debian 10 Buster system. Now check the currently active Java version by running the following command.
java -version java version "11.0.2" 2018-10-16 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)
Step 5 – Configure Java 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
Now, Add/Update following values:
export J2SDKDIR=/usr/lib/jvm/jdk-11.0.2 export J2REDIR=/usr/lib/jvm/jdk-11.0.2 export PATH=$PATH:/usr/lib/jvm/jdk-11.0.2/bin:/usr/lib/jvm/jdk-11.0.2/db/bin export JAVA_HOME=/usr/lib/jvm/jdk-11.0.2 export DERBY_HOME=/usr/lib/jvm/jdk-11.0.2/db
Then save your file and exit. Then load these setting to current active shell also
You have successfully installed Java 11.0.2 on Debian 10 Buster Linux system.