How to replace OpenJDK 6 with OpenJDK 7?

77,662

Solution 1

The problem is that the default-jre package depends on OpenJDK 6 and most other packages have their dependencies defined as default-jre | openjdk-6-jre | sun-java6-jre - so until OpenJDK 7 becomes officially supported and will be used as the default version, or until all Java-dependent packages update their dependencies, you'll have to keep OpenJDK 6 around and set the OpenJDK 7 as default using update-java-alternatives. Example for 64-bit system:

$ update-java-alternatives -l
java-1.6.0-openjdk 1061 /usr/lib/jvm/java-1.6.0-openjdk
java-1.7.0-openjdk-amd64 1051 /usr/lib/jvm/java-1.7.0-openjdk-amd64
$ sudo update-java-alternatives -s java-1.7.0-openjdk-amd64

On 32-bit system the directory name will differ, you can find the right name using the -l switch. The second command may spit a lot of errors; either use --jre switch or just ignore errors – the script changes what it can and just ignores the rest.

One could theoretically edit the default-jre package to depend on OpenJDK 7, but be warned that this can cause more harm than good.

Solution 2

For this, you must have both versions of jdk installed on your system. you can use apt-get to download both.

After that try,

$ sudo update-alternatives --config java

and select the jdk you want to use.

Openjdk is sometimes unfavourable, for some of the applications.

You should also try for oracle-java or sun-java.

The link below is very useful for this purpose:

http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html

Solution 3

OpenJDK 7 is in the normal ubuntu repos in 11.10, if you look for openjdk-7-jre and openjdk-7-jdk and install them using apt-get/synaptic/software centre they should replace openjdk-6, if it doesn't you could remove the openjdk-6-* packages first using apt-get purge openjdk-6-*

Solution 4

The repo can be found here: https://launchpad.net/~openjdk/+archive/ppa

or:

sudo apt-add-repository ppa:openjdk/ppa
sudo apt-get update
sudo apt-get upgrade

assuming you have OpenJDK installed

Share:
77,662

Related videos on Youtube

Ivan
Author by

Ivan

Updated on September 18, 2022

Comments

  • Ivan
    Ivan almost 2 years

    Surprisingly (as OpenJDK 7 was released to general availability about 4 months ago) Ubuntu 11.10 still uses OpenJDK 6 instead of 7 by default. How do I best fix this? I'd prefer to remove OpenJDK 6 completely and let OpenJDK 7 to be the default-jdk and default-jre.

    I don't want the official Oracle tarballs, I want deb repos - the standard Ubuntu way.

    • somasekhar
      somasekhar over 12 years
      Somebody would have to build that into a Debian package and put it into a PPA on Launchpad. If nobody did that yet, you can either make a .deb or install the tar.
    • vaquito
      vaquito about 12 years
      Still the case with 12.04
    • Admin
      Admin about 12 years
      Year 2011 - Now Year 2012 - was this resolved really (which one was considered to be the answer lol? If not i gonna write a nice wiki on this in my question / answer.
    • Darryl Williams
      Darryl Williams over 11 years
      It will be better to upgrade your system to LTS.
    • Admin
      Admin over 10 years
  • Ivan
    Ivan over 12 years
    openjdk-7-* packages seem to be meant to be installed side-by-side with openjdk-6-. And if I try to remove openjdk-6-, there are tons of packages to be removed as dependant (despite the fact I know some of those applications work perfectly with Java 7).
  • Ivan
    Ivan over 12 years
    It seems it is not meant for 11.10.
  • Blair Zajac
    Blair Zajac over 12 years
    To get this to work on precise I had to ensure that for each openjdk-6 or icedtea-6 package there was a corresponding openjdk-7 or icetea-7 package, otherwise update-java-alternatives will fail to make the switch.
  • vaquito
    vaquito about 12 years
    apparently default-jre still points to Java 6.
  • David
    David almost 10 years
    After installing the icedtea-7-plugin ($ sudo apt-get install icedtea-7-plugin) it worked well on Ubuntu 12.04. Thanks.