Java: the way to install it

Daniel Maioni
2 min readMar 23, 2023

As a Java coder, and use many different tools that depends from Java, let’s see how to install it below:

Normally, Java is already installed in a Linux system, but you can install any version you want, the default-java, default-jdk, or from version 8 to 19 with openjdk, it’s up to you, here we gonna install the default one:

sudo apt install default-jdk

The default-jdk, default-java, java-1.11.0-openjdk-amd4… all those are symbolic links to the java version in use, by default they point to java-11-openjdk-amd64, the folder that contains the binaries.

Java JDK versions available right now:

sudo apt install default-jdk
sudo apt install openjdk-8-jdk
sudo apt install openjdk-11-jdk
sudo apt install openjdk-17-jdk
sudo apt install openjdk-19-jdk

Note about Java support for LTS versions:

  • Java 7 until 2022
  • Java 8 until 2030
  • Java 11 until 2026
  • Java 17 until 2029
  • Java 21 until 2031

I like to create mine symbolic link, so we could switch java versions easily, use the command ln adding the parameters s (symbolic) f (force) n (no-dereference)

So, for java 17:

sudo ln -sfn /usr/lib/jvm/java-1.17.0-openjdk-amd64 /usr/lib/jvm/java-in-use
ls -ld /usr/lib/jvm/java-in-use
which java

Configure the environment variables for it:

sudo echo "export JAVA_HOME=/usr/lib/jvm/java-in-use" >> ~/.bashrc
sudo echo "export PATH=$PATH:$JAVA_HOME/bin" >> ~/.bashrc
source ~/.bashrc

And make sure it’s setup:

echo $JAVA_HOME
echo $PATH
java -version

If needed to edit the .basrc open it with nano:

nano ~/.bashrc

press INSERT to enter the edit mode

export JAVA_HOME=/usr/lib/jvm/default-java

and save it with CTRL + X confirming with y key to overwrite it, and load bashrc again.

source ~/.bashrc

If you need to upgrade the link, repeated the process to download the java version needed and update the symbolic link to the new value with sameln command:

sudo ln -sfn /usr/lib/jvm/java-1.19.0-openjdk-amd64 /usr/lib/jvm/java-in-use

But if you do not need it anymore, you can delete the link:

sudo rm /usr/lib/jvm/java-in-use

Done!

A white mug with the Java logo
Java is ready to be consumed!

IT’s my problems, maybe yours…

--

--