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.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
5 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
Bozhidar IvanovSagar SBghaza momoWellington TorrejaisFly Recent comment authors
newest oldest most voted
Sagar SB
Guest
Sagar SB

how to do it same in Windows 7 Laptop ?

Bozhidar Ivanov
Guest
Bozhidar Ivanov

Control Panel > Java

ghaza momo
Guest
ghaza momo

Thanks mate !!

trackback
How to Install Oracle JDK 8 On Debian

[…] Debian : Change default Java version […]

Wellington Torrejais
Guest
Wellington Torrejais

Work Fine! Thanks!!!

Fly
Guest
Fly

Hi Mkyong,

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

Regards.
Fly
:o )