Java 7 on Ubuntu 11.04

So after 5+ years, we finally have a new version of Java. In spite of mixed reviews, as a software engineer working a lot on the JVM, I still wanted to take it for a spin. However, being an Ubuntu user, this involves a tad bit of work since there are only RPM and binary packages available at this time.

So until there are official or unofficial .deb packages available, we're going to have to sneak in the raw binaries outselves. The following is how I did this on my 64bit Ubuntu 11.04 system. I take no responsibility in breaking your existing Java installation yada yada, you do this at your own responsibility.

Procedure
Start by downloading the binary.

casper@workstation:~$ wget http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz

Then unpack it.

casper@workstation:~$ tar -xzf jdk-7-linux-x64.tar.gz

Remove packed archive and move/rename the extracted folder into something a little more Ubuntu appropiate.

casper@workstation:~$ sudo rm java-7-sun-1.7.0.tar.gz
casper@workstation:~$ sudo mv jdk1.7.0 /usr/lib/jvm/java-7-sun-1.7.0

Follow the Ubuntu tradition, by symlinking a generic major java version to a concrete minor version.

casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun-1.7.0 /usr/lib/jvm/java-7-sun

Override Ubuntu's standard alternatives mechanism, replacing links to Java 6 with links to Java 7. It would be better to use the update-alternatives tools available in Ubuntu, but I was unable to make this work. If you screw something up here, you may have to uninstall and reinstall your JDK/JRE stuff, in order to revert to a working Java installation.

Delete any existing symlinks.

casper@workstation:~$ sudo rm /etc/alternatives/java
casper@workstation:~$ sudo rm /etc/alternatives/javac
casper@workstation:~$ sudo rm /etc/alternatives/javadoc
casper@workstation:~$ sudo rm /etc/alternatives/javah
casper@workstation:~$ sudo rm /etc/alternatives/javap
casper@workstation:~$ sudo rm /etc/alternatives/javaws
casper@workstation:~$ sudo rm /etc/alternatives/java_vm

Create the new symlinks.

casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/jre/bin/java /etc/alternatives/java
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javac /etc/alternatives/javac
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javadoc /etc/alternatives/javadoc
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javah /etc/alternatives/javah
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javap /etc/alternatives/javap
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javaws /etc/alternatives/javaws
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/jre/bin/java_vm /etc/alternatives/java_vm

Finally, we may aid various client software in locating where Java in installed, by adding a few environment variables. Do this by editing .bashrc in your home directory.

casper@workstation:~$ gksudo gedit $HOME/.bashrc

Scroll down to the end of the file and add two new lines:

export JDK_HOME=/usr/lib/jvm/java-7-sun
export JAVA_HOME=$JDK_HOME

Restart and that's pretty much it, this worked for me, hope it works for you too. Otherwise, throw me a comment below.

Update: If you are unable to run applets wtihin your browsers, this may be caused by the existing Java Plug-in 1.6 clashing with the new incompatible JRE 1.7 you just installed. To remidy this, you can launch the Java Control Panel and disable the JRE 1.7, making 1.6 the only (and thus default) one.


As you can see below, you still retain Java 1.7, but applets and webstart won't try to use any of this new stuff.


Comments

Unknown said…
I'd follow all steps, as you wrote, but when i run 'java -version'
it writes
timopheym@timophey:~$ java -version
bash: /usr/bin/java: cannot execute binary file
and when i do it by root:
timopheym@timophey:~$ sudo java -version
[sudo] password for timopheym:
/usr/bin/java: 1: Syntax error: "(" unexpected

Where i'm wrong?
Casper Bang said…
I'm not sure what your problem is Тим, except that you could try to give it execute permission if it does not already have that (chmod +x).

I suspect there could also be a platform issue involved, i.e. are you sure you're using a 64bit JRE with a 64bit version of Ubuntu?
I propose one way to make easier the installation of Oracle's Java 7.

Since Ubuntu does not provides the Oracle's Java 7 packages,
I'm providing a collection of Ubuntu packages on my own package repository.

The packages are fully integrated in the Ubuntu way to support Java.
You will be able to select the Oracle's Java 7 alternative with
the standard tools: update-alternative or update-java-alternative.

The main page of my contribution is: http://www.arakhne.org/jdk/index.html

To obtain the packages, you only need to add my package repository into your system configuration.
The process is explained in http://www.arakhne.org/ubuntu.html

Popular posts from this blog

Oracle SQLDeveloper 4 on Debian/Ubuntu/Mint

@SuppressWarnings values

Rejsekort Scanner