Hello, friends. Old rockers never die and that’s why languages like Java don’t either. Many important tools are created in this language. In this post, you will learn quickly and easily how to install Java on Debian 11. This post can be the basis for you to get into this programming language. Besides this, it is also the basis for the installation of many other applications.
Java is one of the preferred languages by many developers but it is also necessary to run other very important software. In this sense, Oracle from time to time releases a new version that includes good news.
So, if you are a developer and want to try Java on Debian 11, this post will help you with that.
Install Java on Debian 11
In the Debian 11 stable repositories we have the presence of OpenJDK which is a free Java implementation. We will be able to use and install it without compatibility problems because it is the same as the version distributed by Oracle.
For the sake of stability and compatibility with most applications, Debian 11 includes Java 11. This version besides being LTS is the base on which many important applications have been built.
So, this is the version we will install.
To install both the JDK (Java Development Kit) and the JRE (Java Runtime Environment) just execute in a terminal this pair of commands
sudo apt update sudo apt install default-jdk Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: ca-certificates-java default-jdk-headless default-jre default-jre-headless fontconfig-config fonts-dejavu-core java-common libasound2 libasound2-data libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-common libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libfontconfig1 libgif7 libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libgraphite2-3 libharfbuzz0b libjpeg62-turbo liblcms2-2 libllvm11 libnspr4 libnss3 libpciaccess0 libpcsclite1 libsensors-config libsensors5 libvulkan1 libx11-6 libx11-data libx11-xcb1 libxau6 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxrender1 libxshmfence1 libxtst6 libxxf86vm1 libz3-4 openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11-common Suggested packages: libasound2-plugins alsa-utils cups-common liblcms2-utils pciutils pcscd lm-sensors openjdk-11-demo openjdk-11-source visualvm libnss-mdns fonts-dejavu-extra fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei fonts-indic Recommended packages: alsa-ucm-conf alsa-topology-conf mesa-vulkan-drivers | vulkan-icd libxt-dev libatk-wrapper-java-jni fonts-dejavu-extra The following NEW packages will be installed: ca-certificates-java default-jdk default-jdk-headless default-jre default-jre-headless fontconfig-config fonts-dejavu-core java-common libasound2 libasound2-data libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-common libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libfontconfig1 libgif7 libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libgraphite2-3 libharfbuzz0b libjpeg62-turbo liblcms2-2 libllvm11 libnspr4 libnss3 libpciaccess0 libpcsclite1 libsensors-config libsensors5 libvulkan1 libx11-6 libx11-data libx11-xcb1 libxau6 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxrender1 libxshmfence1 libxtst6 libxxf86vm1 libz3-4 openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11-common 0 upgraded, 67 newly installed, 0 to remove and 2 not upgraded. Need to get 306 MB of archives. After this operation, 574 MB of additional disk space will be used. Do you want to continue? [Y/n]
In case you only want to install the JRE which is enough to run certain applications made with Java,
sudo apt install default-jre
At the end of the process, Java will be installed on your computer.
Configuring the Environment Variable
Once Java is installed, it is a good idea to set the JAVA_HOME
environment variable that tells the system the path where Java is installed. This step, although optional for this post, may be necessary when installing more complex applications.
So, to know where JAVA is installed, just run the following command
sudo update-alternatives --config java
There you will be shown a screen where you can choose between several versions of Java installed. Of course, in this case, you should only see version 11 that was installed, but the important thing is that it will also show you the path where it will be.
In this case OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java
.
With this information, we can edit the /etc/environment
file.
sudo nano /etc/environment
And add the following to the end of the file
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Save the changes and close the text editor.
Apply the changes
source /etc/environment
Finally, the environment variable has been set correctly. To demonstrate this, run
echo $JAVA_HOME
Sample Output:
/usr/lib/jvm/java-11-openjdk-amd64
So, Java is installed without problems. Enjoy it!