5 years ago

Manually Install Oracle JDK 6 on Ubuntu 12.10

I very recently setup a new development virtual machine running Ubuntu 12.04 LTS.  I tend to create a new VM and configure it exactly the same as the deployment server for the particular project I am working on. This ensures I am aware of any subtle issues which may effect deployment.
As the language for this project was PHP I wanted to configure NetBeans, as its probably one of the best IDEs for PHP.  I like all the niceties like code-completion, refactoring tools and code navigation.  The most recent version of NetBeans is version 7.2.1 which has a requirement of a Java 6 JDK.  The package manager in Ubuntu 12.04 LTS has references to implementations of Java 6 or 7, but both of these are from the OpenJDK project.  Since 2010 when Oracle aquired Sun Microsystems many distros including Ubuntu have dropped Sun JDK in favour of OpenJDK as the Sun JDK is no longer fully open source.
Nevertheless I wanted to get running with the Oracle implementation of JDK 6.  If you have a dig around online for instructions for doing this you will find that most instructions refer to using the out of date sun-java6-jdk or using a .ppm.  I wasn't able to find a ppm solution that worked correctly so I did a manual installation, here are my notes.
  1. Firstly grab the Linux self extractor from Oracle here (I downloaded JDK 6 Update 37).
  2. Once the download is complete fire up the terminal and make the self extractor executable by navigating to your download folder and running
    (The download filename will vary depending on which version you download so replace 'jdk-6u37-linux-i586.bin' with the name of the jdk you download)
    chmod a+x jdk-6u37-linux-i586.bin 
  3. Ubuntu 12.04 LTS doesn't have a JVM folder so create one
    sudo mkdir /usr/lib/jvm 
  4. Now move the binary into the newly created jvm folder
    sudo mv jdk-6u37-linux-i586.bin /usr/lib/jvm/ 
  5. Run the extractor
    sudo /usr/lib/jvm/jdk-6u37-linux-i586.bin
    The contents of the binary will be extracted to the /usr/lib/jvm folder in a folder named dependant on the version of the JDK you download (In this case it was 'jdk1.6.0_37').
  6. Create symbolic links for the OS to point to the JVM.
    sudo ln -s -b /usr/lib/jvm/jdk1.6.0_37/jre/bin/java /etc/alternatives/java
    sudo ln -s -b /usr/lib/jvm/jdk1.6.0_37/jre/bin/java /usr/bin/java
  7. Now you can remove the self extracting binary file
    sudo rm /usr/lib/jvm/jdk-6u37-linux-i586.bin 
  8. Now run java to check version
    java -version 
  9. Enjoy!