Set JDK 8 as the default Java on Debian 8

32,303

Solution 1

update-java-alternatives has options to update --jre-headless, --jre, and --plugin separately.

Using

sudo update-java-alternatives --jre-headless --jre --set java-1.8.0-openjdk-amd64

worked for me on a Debian Jessie server with no plugin installed.

Solution 2

In ubuntu, JDK1.8 does not stay installed by default. When you list for java alternatives

$ update-java-alternatives -l
java-1.11.0-openjdk-amd64      1101       /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64       1081       /usr/lib/jvm/java-1.8.0-openjdk-amd64
java-7-oracle                  1082       /usr/lib/jvm/java-7-oracle

java-1.8.0-openjdk-amd64 in this list is not JDK, but JRE instead. JRE doesn't contain all the necessary development tools like javac, javadoc, etc. You can verify if the bin directory contains these files. This is the reason of not registering these tools.

So, first you have to install JDK

sudo apt install openjdk-8-jdk

And then change the alternative

sudo update-java-alternatives -s java-1.8.0-openjdk-amd64

Solution 3

The easiest way to achieve this in Debian is using this command

update-alternatives --config java

Then you will get a output like this:

*0  /usr/lib/jvm/java-8-openjdk-amd64/bin/java  auto mode
 1  /usr/lib/jvm/jdk1.7.0/bin/java              manual mode

Then you can change your default selection (marked with "*") by typing the index number. For example you select "1" in order to use Java 7 as default JVM. You can run the command again in order to check changes.

Hope it helps.

Solution 4

For Linux (e.g. Debian):

# update-alternatives --config java
# update-alternatives --config javac
# update-alternatives --config javaws

Example:

$ sudo update-alternatives --config java
There are 4 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-10-oracle/bin/java             1091      auto mode
* 1            /usr/lib/jvm/java-10-oracle/bin/java             1091      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1081      manual mode
  4            /usr/lib/jvm/jdk1.7.0_80/bin/java                1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
Share:
32,303

Related videos on Youtube

Edd Barrett
Author by

Edd Barrett

Computer scientist, programmer.

Updated on September 18, 2022

Comments

  • Edd Barrett
    Edd Barrett over 1 year

    I'm trying to set the Java SDK 8 tools (installed from the debian backports repo) as the defaults.

    # update-java-alternatives --list
    java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
    java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64
    
    # update-java-alternatives --set /usr/lib/jvm/java-1.8.0-openjdk-amd64
    update-alternatives: error: no alternatives for mozilla-javaplugin.so
    update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
    

    Hum, well aside from that error (which I am lead to believe is merely a warning according to https://askubuntu.com/questions/141791/is-there-a-way-to-update-all-java-related-alternatives . If not, I don't know how to fix this, as there is no icedtea plugin for jdk8 that I can see), this should have done the trick, right?

    But many Java tools still point to Java 7:

    # update-alternatives --get-selections | grep java
    appletviewer                   manual   /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer
    extcheck                       auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/extcheck
    idlj                           auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/idlj
    jar                            auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/jar
    jarsigner                      auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/jarsigner
    java                           manual   /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
    javac                          auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
    javadoc                        auto     /usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc
    ...
    

    What gives? Broken?

    EDIT:

    Worked around this with:

    for i in `update-alternatives --get-selections | grep java | awk '{print $1}'`; do update-alternatives --config $i; done
    

    This will manually prompt you for each and every tool. Which takes about a minute. Still, I would like to know if there is a better way.