How to Configure Java on Debian Linux

Sarwan Soomro Feb 02, 2024
  1. Install Java 11 and Java 8 on Debian Linux
  2. Importance of Command Alternatives --Config in Debian System
  3. Use Debian Command update-alternatives --config java
  4. Use Update Alternatives –Config to Choose Between Manual and Auto Modes on Linux
How to Configure Java on Debian Linux

We will use bash shell Linux Debian apt-get commands to download two open JDK versions.

  1. OpenJDK version 11
  2. OpenJDK version 8

Then we will use update-alternatives --config to change the JDK version. You can update --config JDK versions on Ubuntu Linux, Debian Linux, and Virtual Boxes (Linux).

Those with Windows 10 (64bits) can use Debian or Ubuntu bash shell from the Microsoft Store.

Install Java 11 and Java 8 on Debian Linux

  • Use java -version to check the current Java version.
    openjdk version "1.8.0_252"
    OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~deb9u1-b09)
    OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
    
  • Update system
    sudo apt-get update
    
  • Install JDK 11+
    sudo apt-get install default-jdk
    
  • Install JDK 8
    sudo apt-get install openjdk-8-jdk
    

If you encounter: JDK version not found error while installing your Java version on Debian, read below.

Resolve Most Common Java Installation Errors on Debian Linux

  • Type in:
    nano /etc/apt/sources.list
    
  • Copy the text below, and paste it into the repository.
    deb http://ftp.us.debian.org/debian stretch main contrib non-free
    
  • After that, do not forget to press CTRL+X and then press y and then press Enter.

    Check this demo of the whole process.

    resolve repository issue to avoid jdk installation most common error

    Since you have set your Debian repository, we are sure you will install all the Java versions.

Importance of Command Alternatives --Config in Debian System

This Debian Linux shell command allows users to choose between the installed versions. In the case of Java JDKs, it will enable you to set preferences.

Whenever you update --config, the default setting will affect the selected version until you reset it using the same update --config commands.

The update-alternatives --config java works perfectly fine on the Debian 1.12.1.0 version available on the Microsoft Store.

If you are a Debian Linux user, you do not need to use bash shell commands. Similarly, you can do the same on Oracle Virtual Machine for Windows (after installing the ISO file of your favorite Linux).

Use Debian Command update-alternatives --config java

Now that you have made sure that you have installed Java versions on your Linux system. All you must do is type the command below.

update-alternatives --config java

If you get this output:

$ update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Nothing to configure.

You have only one symbolic link and nothing to choose from to configure; however, you have two Java Versions installed, like in our case for this demo.

The output will be:

update-alternatives –config java

Use Update Alternatives –Config to Choose Between Manual and Auto Modes on Linux

The real purpose of these commands is to allow you to choose between different versions (JDK in this case). So, how do you determine what version to choose?

Well, it depends on the user. The system is straightforward; it does what it says.

It will list out the installed JDK version.

sudo update-alternatives --list javac
/usr/lib/jvm/java-11-openjdk-amd64/bin/javac
/usr/lib/jvm/java-8-openjdk-amd64/bin/javac

The sudo update-alternatives --config javac or sudo update-alternatives --config java command both worked fine on Debian Linux. Now see the bash output below.

sudo update-alternatives –config javac

The current version is Java-11. We chose the number 2.

See the output now.

java-8 current version

As you can see, the current version is Java-8 now.

This method is how you can effortlessly use update-alternatives --config java on Linux.

debian command update-alternatives –config javac output

Sarwan Soomro avatar Sarwan Soomro avatar

Sarwan Soomro is a freelance software engineer and an expert technical writer who loves writing and coding. He has 5 years of web development and 3 years of professional writing experience, and an MSs in computer science. In addition, he has numerous professional qualifications in the cloud, database, desktop, and online technologies. And has developed multi-technology programming guides for beginners and published many tech articles.

LinkedIn