Debian : Change default Java version

Deployed a Debian 7.5 on Linode server, the default is using OpenJDK 1.6. How to upgrade to OpenJDK 1.7?


$ java -version
java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1~deb7u1)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

Tracing the java, it’s using the Debian’s alternative settings :


$ ls -lsa /usr/bin/ | grep java
0 lrwxrwxrwx  1 root   root    22 Jul  9 03:50 java -> /etc/alternatives/java

$ ls -lsa /etc/alternatives/java
0 lrwxrwxrwx 1 root root 46 Jul 12 23:02  /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java

Solution

On Debian, you can use update-alternatives to configure Java :

Note
Understand the Debian alternatives system

1. Install OpenJDK 1.7


$ sudo apt-get install openjdk-7-jdk openjdk-7-jre

2. Update Java alternative path :


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

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode

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

$ java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1~deb7u1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

Done.

6 comments on “Debian : Change default Java version

  1. Generally you should run update-java-alternatives instead of update-alternatives.

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

    this will update all java programs, java, javac, jar, jcmd, etc ,etc

    Reply
  2. Hi Mkyong,

    Thanks a lot for this short but efficient post : Now, everything is OK on my laptop…

    Regards.
    Fly
    😮 )

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *