Install Oracle Java SDK in Ubuntu 11.10

Installing Oracle Java SDK in Ubuntu is a pain because not so long ago Oracle decided to change licensing of Java. Which in the long run will hurt only users. Distributions can no longer make automated installs of Oracle Java, users are required to agree with the license displayed on Oracle’s web site. Installing Java SDK in a ‘proper Ubuntu way’ is now a little bit tricky. Read on to learn how to do it.

Instructions were written on x64 so if you are running 32bit version of Ubuntu, adjust accordingly. First, you will need Oracle Java SDK which you can get here. Extract it in /usr/lib/jvm directory and give the newly created directory a pretty name and a symlink:

$ cd /usr/lib/jvm/
$ sudo tar -xvzf ~/jdk-7-linux-x64.tar.gz
$ sudo mv jdk1.7.0 java-7-oracle
$ sudo ln -s java-7-oracle java-1.7.0-oracle

Now, create a file .java-1.7.0-oracle.jinfo in /usr/lib/jvm with the following contents:

alias=java-7-oracle
priority=100
section=non-free
 
jre ControlPanel /usr/lib/jvm/java-7-oracle/jre/bin/ControlPanel
jre java /usr/lib/jvm/java-7-oracle/jre/bin/java
jre java_vm /usr/lib/jvm/java-7-oracle/jre/bin/java_vm
jre javaws /usr/lib/jvm/java-7-oracle/jre/bin/javaws
jre jcontrol /usr/lib/jvm/java-7-oracle/jre/bin/jcontrol
jre keytool /usr/lib/jvm/java-7-oracle/jre/bin/keytool
jre pack200 /usr/lib/jvm/java-7-oracle/jre/bin/pack200
jre policytool /usr/lib/jvm/java-7-oracle/jre/bin/policytool
jre rmid /usr/lib/jvm/java-7-oracle/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/java-7-oracle/jre/bin/rmiregistry
jre unpack200 /usr/lib/jvm/java-7-oracle/jre/bin/unpack200
jre orbd /usr/lib/jvm/java-7-oracle/jre/bin/orbd
jre servertool /usr/lib/jvm/java-7-oracle/jre/bin/servertool
jre tnameserv /usr/lib/jvm/java-7-oracle/jre/bin/tnameserv
jre jexec /usr/lib/jvm/java-7-oracle/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/java-7-oracle/bin/appletviewer
jdk apt /usr/lib/jvm/java-7-oracle/bin/apt
jdk extcheck /usr/lib/jvm/java-7-oracle/bin/extcheck
jdk idlj /usr/lib/jvm/java-7-oracle/bin/idlj
jdk jar /usr/lib/jvm/java-7-oracle/bin/jar
jdk jarsigner /usr/lib/jvm/java-7-oracle/bin/jarsigner
jdk java-rmi.cgi /usr/lib/jvm/java-7-oracle/bin/java-rmi.cgi
jdk javac /usr/lib/jvm/java-7-oracle/bin/javac
jdk javadoc /usr/lib/jvm/java-7-oracle/bin/javadoc
jdk javah /usr/lib/jvm/java-7-oracle/bin/javah
jdk javap /usr/lib/jvm/java-7-oracle/bin/javap
jdk jconsole /usr/lib/jvm/java-7-oracle/bin/jconsole
jdk jdb /usr/lib/jvm/java-7-oracle/bin/jdb
jdk jhat /usr/lib/jvm/java-7-oracle/bin/jhat
jdk jinfo /usr/lib/jvm/java-7-oracle/bin/jinfo
jdk jmap /usr/lib/jvm/java-7-oracle/bin/jmap
jdk jps /usr/lib/jvm/java-7-oracle/bin/jps
jdk jrunscript /usr/lib/jvm/java-7-oracle/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/java-7-oracle/bin/jsadebugd
jdk jstack /usr/lib/jvm/java-7-oracle/bin/jstack
jdk jstat /usr/lib/jvm/java-7-oracle/bin/jstat
jdk jstatd /usr/lib/jvm/java-7-oracle/bin/jstatd
jdk native2ascii /usr/lib/jvm/java-7-oracle/bin/native2ascii
jdk rmic /usr/lib/jvm/java-7-oracle/bin/rmic
jdk schemagen /usr/lib/jvm/java-7-oracle/bin/schemagen
jdk serialver /usr/lib/jvm/java-7-oracle/bin/serialver
jdk wsgen /usr/lib/jvm/java-7-oracle/bin/wsgen
jdk wsimport /usr/lib/jvm/java-7-oracle/bin/wsimport
jdk xjc /usr/lib/jvm/java-7-oracle/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so
plugin mozilla-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so

After you created the file, you will need to tell the system about your new Java. For this you will have to use a bunch of pretty cryptic commands.

$ sudo -sH
update-alternatives --quiet --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so 100
update-alternatives --quiet --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so 100
update-alternatives --quiet --install /usr/bin/appletviewer appletviewer /usr/lib/jvm/java-7-oracle/bin/appletviewer 100 --slave /usr/share/man/man1/appletviewer.1 appletviewer.1 /usr/lib/jvm/java-7-oracle/man/man1/appletviewer.1
update-alternatives --quiet --install /usr/bin/apt apt /usr/lib/jvm/java-7-oracle/bin/apt 100 --slave /usr/share/man/man1/apt.1 apt.1 /usr/lib/jvm/java-7-oracle/man/man1/apt.1
update-alternatives --quiet --install /usr/bin/extcheck extcheck /usr/lib/jvm/java-7-oracle/bin/extcheck 100 --slave /usr/share/man/man1/extcheck.1 extcheck.1 /usr/lib/jvm/java-7-oracle/man/man1/extcheck.1
update-alternatives --quiet --install /usr/bin/idlj idlj /usr/lib/jvm/java-7-oracle/bin/idlj 100 --slave /usr/share/man/man1/idlj.1 idlj.1 /usr/lib/jvm/java-7-oracle/man/man1/idlj.1
update-alternatives --quiet --install /usr/bin/jar jar /usr/lib/jvm/java-7-oracle/bin/jar 100 --slave /usr/share/man/man1/jar.1 jar.1 /usr/lib/jvm/java-7-oracle/man/man1/jar.1
update-alternatives --quiet --install /usr/bin/jarsigner jarsigner /usr/lib/jvm/java-7-oracle/bin/jarsigner 100 --slave /usr/share/man/man1/jarsigner.1 jarsigner.1 /usr/lib/jvm/java-7-oracle/man/man1/jarsigner.1
update-alternatives --quiet --install /usr/bin/javac javac /usr/lib/jvm/java-7-oracle/bin/javac 100 --slave /usr/share/man/man1/javac.1 javac.1 /usr/lib/jvm/java-7-oracle/man/man1/javac.1
update-alternatives --quiet --install /usr/bin/javadoc javadoc /usr/lib/jvm/java-7-oracle/bin/javadoc 100 --slave /usr/share/man/man1/javadoc.1 javadoc.1 /usr/lib/jvm/java-7-oracle/man/man1/javadoc.1
update-alternatives --quiet --install /usr/bin/javah javah /usr/lib/jvm/java-7-oracle/bin/javah 100 --slave /usr/share/man/man1/javah.1 javah.1 /usr/lib/jvm/java-7-oracle/man/man1/javah.1
update-alternatives --quiet --install /usr/bin/javap javap /usr/lib/jvm/java-7-oracle/bin/javap 100 --slave /usr/share/man/man1/javap.1 javap.1 /usr/lib/jvm/java-7-oracle/man/man1/javap.1
update-alternatives --quiet --install /usr/bin/jconsole jconsole /usr/lib/jvm/java-7-oracle/bin/jconsole 100 --slave /usr/share/man/man1/jconsole.1 jconsole.1 /usr/lib/jvm/java-7-oracle/man/man1/jconsole.1
update-alternatives --quiet --install /usr/bin/jdb jdb /usr/lib/jvm/java-7-oracle/bin/jdb 100 --slave /usr/share/man/man1/jdb.1 jdb.1 /usr/lib/jvm/java-7-oracle/man/man1/jdb.1
update-alternatives --quiet --install /usr/bin/jhat jhat /usr/lib/jvm/java-7-oracle/bin/jhat 100 --slave /usr/share/man/man1/jhat.1 jhat.1 /usr/lib/jvm/java-7-oracle/man/man1/jhat.1
update-alternatives --quiet --install /usr/bin/jinfo jinfo /usr/lib/jvm/java-7-oracle/bin/jinfo 100 --slave /usr/share/man/man1/jinfo.1 jinfo.1 /usr/lib/jvm/java-7-oracle/man/man1/jinfo.1
update-alternatives --quiet --install /usr/bin/jmap jmap /usr/lib/jvm/java-7-oracle/bin/jmap 100 --slave /usr/share/man/man1/jmap.1 jmap.1 /usr/lib/jvm/java-7-oracle/man/man1/jmap.1
update-alternatives --quiet --install /usr/bin/jps jps /usr/lib/jvm/java-7-oracle/bin/jps 100 --slave /usr/share/man/man1/jps.1 jps.1 /usr/lib/jvm/java-7-oracle/man/man1/jps.1
update-alternatives --quiet --install /usr/bin/jrunscript jrunscript /usr/lib/jvm/java-7-oracle/bin/jrunscript 100 --slave /usr/share/man/man1/jrunscript.1 jrunscript.1 /usr/lib/jvm/java-7-oracle/man/man1/jrunscript.1
update-alternatives --quiet --install /usr/bin/jsadebugd jsadebugd /usr/lib/jvm/java-7-oracle/bin/jsadebugd 100 --slave /usr/share/man/man1/jsadebugd.1 jsadebugd.1 /usr/lib/jvm/java-7-oracle/man/man1/jsadebugd.1
update-alternatives --quiet --install /usr/bin/jstack jstack /usr/lib/jvm/java-7-oracle/bin/jstack 100 --slave /usr/share/man/man1/jstack.1 jstack.1 /usr/lib/jvm/java-7-oracle/man/man1/jstack.1
update-alternatives --quiet --install /usr/bin/jstat jstat /usr/lib/jvm/java-7-oracle/bin/jstat 100 --slave /usr/share/man/man1/jstat.1 jstat.1 /usr/lib/jvm/java-7-oracle/man/man1/jstat.1
update-alternatives --quiet --install /usr/bin/jstatd jstatd /usr/lib/jvm/java-7-oracle/bin/jstatd 100 --slave /usr/share/man/man1/jstatd.1 jstatd.1 /usr/lib/jvm/java-7-oracle/man/man1/jstatd.1
update-alternatives --quiet --install /usr/bin/native2ascii native2ascii /usr/lib/jvm/java-7-oracle/bin/native2ascii 100 --slave /usr/share/man/man1/native2ascii.1 native2ascii.1 /usr/lib/jvm/java-7-oracle/man/man1/native2ascii.1
update-alternatives --quiet --install /usr/bin/rmic rmic /usr/lib/jvm/java-7-oracle/bin/rmic 100 --slave /usr/share/man/man1/rmic.1 rmic.1 /usr/lib/jvm/java-7-oracle/man/man1/rmic.1
update-alternatives --quiet --install /usr/bin/schemagen schemagen /usr/lib/jvm/java-7-oracle/bin/schemagen 100 --slave /usr/share/man/man1/schemagen.1 schemagen.1 /usr/lib/jvm/java-7-oracle/man/man1/schemagen.1
update-alternatives --quiet --install /usr/bin/serialver serialver /usr/lib/jvm/java-7-oracle/bin/serialver 100 --slave /usr/share/man/man1/serialver.1 serialver.1 /usr/lib/jvm/java-7-oracle/man/man1/serialver.1
update-alternatives --quiet --install /usr/bin/wsgen wsgen /usr/lib/jvm/java-7-oracle/bin/wsgen 100 --slave /usr/share/man/man1/wsgen.1 wsgen.1 /usr/lib/jvm/java-7-oracle/man/man1/wsgen.1
update-alternatives --quiet --install /usr/bin/wsimport wsimport /usr/lib/jvm/java-7-oracle/bin/wsimport 100 --slave /usr/share/man/man1/wsimport.1 wsimport.1 /usr/lib/jvm/java-7-oracle/man/man1/wsimport.1
update-alternatives --quiet --install /usr/bin/xjc xjc /usr/lib/jvm/java-7-oracle/bin/xjc 100 --slave /usr/share/man/man1/xjc.1 xjc.1 /usr/lib/jvm/java-7-oracle/man/man1/xjc.1
update-alternatives --quiet --install /usr/bin/java-rmi.cgi java-rmi.cgi /usr/lib/jvm/java-7-oracle/bin/java-rmi.cgi 100
update-alternatives --quiet --install /usr/bin/ControlPanel ControlPanel /usr/lib/jvm/java-7-oracle/jre/bin/ControlPanel 100
update-alternatives --quiet --install /usr/bin/java java /usr/lib/jvm/java-7-oracle/jre/bin/java 100
update-alternatives --quiet --install /usr/bin/java_vm java_vm /usr/lib/jvm/java-7-oracle/jre/bin/java_vm 100
update-alternatives --quiet --install /usr/bin/javaws javaws /usr/lib/jvm/java-7-oracle/jre/bin/javaws 100
update-alternatives --quiet --install /usr/bin/jcontrol jcontrol /usr/lib/jvm/java-7-oracle/jre/bin/jcontrol 100
update-alternatives --quiet --install /usr/bin/keytool keytool /usr/lib/jvm/java-7-oracle/jre/bin/keytool 100
update-alternatives --quiet --install /usr/bin/pack200 pack200 /usr/lib/jvm/java-7-oracle/jre/bin/pack200 100
update-alternatives --quiet --install /usr/bin/policytool policytool /usr/lib/jvm/java-7-oracle/jre/bin/policytool 100
update-alternatives --quiet --install /usr/bin/rmid rmid /usr/lib/jvm/java-7-oracle/jre/bin/rmid 100
update-alternatives --quiet --install /usr/bin/rmiregistry rmiregistry /usr/lib/jvm/java-7-oracle/jre/bin/rmiregistry 100
update-alternatives --quiet --install /usr/bin/unpack200 unpack200 /usr/lib/jvm/java-7-oracle/jre/bin/unpack200 100
update-alternatives --quiet --install /usr/bin/orbd orbd /usr/lib/jvm/java-7-oracle/jre/bin/orbd 100
update-alternatives --quiet --install /usr/bin/servertool servertool /usr/lib/jvm/java-7-oracle/jre/bin/servertool 100
update-alternatives --quiet --install /usr/bin/tnameserv tnameserv /usr/lib/jvm/java-7-oracle/jre/bin/tnameserv 100
update-alternatives --quiet --install /usr/bin/jexec jexec /usr/lib/jvm/java-7-oracle/jre/lib/jexec 100

At last you can use update-alternatives to select newly installed Java SDK. When you run the first command, make sure that you select the newly installed Java SDK. At the end, don’t forget to exit from the root shell.

# update-alternatives --config java
# update-java-alternatives --set java-1.7.0-oracle
# exit

This worked for me and now I am able to switch between the Open JDK and Oracle JDK. Easier than eating pancakes, right? ;)


  • update-alternatives: error: no alternatives for -javaplugin.so.

    This is the output of the last command (update-java-alternatives)

    Thanks for the post though – very sad that Oracle is changing its licensing.

    Reply
    • Strange, I’ll double check all the lines in case I messed up something while copy/pasting. :>

      Are you doing this on Ubuntu 11.10?

      Reply
      • Thanks for the great post.

        I get the same error. I’m on a clean install of 11.10.

        # update-java-alternatives –set java-1.7.0-oracle
        update-alternatives: error: no alternatives for -javaplugin.so.

        Is something not installed?

        Reply
  • This works (it changes /etc/alternatives/java to Oracles Java) but

    FYI:

    root@home-linux:~# update-alternatives –quiet –install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so 100
    update-alternatives: error: unable to make /usr/lib/xulrunner-addons/plugins/libjavaplugin.so.dpkg-tmp a symlink to /etc/alternatives/xulrunner-1.9-javaplugin.so: No such file or directory

    This reminds me how much I hate java….

    Reply
  • About the recent errors. I was doing my install on a clean 11.10, but I did have OpenJDK installed previously.

    Reply
    • I also had OpenJDK installed. Even though I got the error, Firefox and Chrome were both still using the Oracle Java 7.

      Reply
  • Clean install of Oneiric here too, but mine seemed to have come with OpenJDK6 by default (DVD iso?).

    The last line of my /usr/lib/jvm/.java-1.6.0-openjdk.jinfo seems to indicate the reason.

    plugin -javaplugin.so /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/IcedTeaPlugin.so

    So…what now?

    Reply
  • Thank you very much, that was really easy :D

    Reply
  • On January 21, 2012 at 14:00 Tamas Imrei said:

    It worked perfectly, thanks!

    Reply
  • On March 10, 2012 at 04:34 BillR said:

    Seriously, I don’t know why you are doing this. Just unzip it to opt, and set the path and java home to point to the directories there. I don’t know any developers who would bother to do this the ‘ubuntu way’. None. Nadda. Zip. Zilch. Narry a one. In fact I and anyone I know avoid any of the distributions install packages so that I can just download the java sdk and unzip it to a directory. It makes life simpler and is easier to develop with etc. If you develop you should NEVER set the class path in your system. You lose too much control over your environment. Anyway as much word as you seem to have done, this seems needless and in fact wrong headed. Much like the way distributions seem to want to force their view of java on people. Just wrong.

    Reply
    • Well, I can switch between different Java versions with a simple command and I don’t have to deal with class path each time I run a program.

      And if you don’t like ‘the ubuntu way’ you can always switch to Arch. ;)

      Reply