Sun Java SDK on Ubuntu or Debian

Problem
I’m using some software that relies on Sun-only code such as BASE64Decoder. I need to use the Sun Microsystems JVM (and SDK), but I couldn’t uninstall GCJ, the existing JVM.
Solution
  1. Get the installation file from Sun’s website.
    1. Go to java.sun.com
    2. Click “J2SE 5.0” (or current version) in the Popular Downloads bar to the right.
    3. Click the “Download JDK 5.0” link in the second section or so (not the JRE link).
    4. Accept the license agreement and download the “Linux self-extracting file” to the Desktop
  2. Make sure you have java-package and fakeroot on your system:
    1. Update your respositories before installing java-package sudo apt-get update (or through Synaptic: Edit -> Reload Package Information)
    2. Install java-package sudo apt-get install java-package (or through Synaptic)
    3. Install fakeroot sudo apt-get install fakeroot (or through Synaptic)
  3. Create a Debian package: fakeroot make-jpkg jdk-1_5_0_05-linux-i586.bin
  4. Install the package: dpkg -i sun-j2sdk1.5_1.5.0+update05_i386.deb
  5. Create a link to the JDK (makes for an easier upgrade process – just repoint the link): ln -s /usr/lib/j2sdk1.5-sun /usr/lib/java
  6. Uninstall GCJ packages to let the Sun binaries be used instead. Do a search in Synaptic for “gcj” and uninstall each of the installed items listed. Skip those that would uninstall a large list of other packages such as alien and OpenOffice. I found that the ones to skip were libgcj6 and libgcj-common.
  7. Set your global environment variables: sudo gedit /etc/profile In this file you need to replace “export PATH” with the following text:
    export PATH

    JAVA_HOME="/usr/lib/java"
    export JAVA_HOME

    CLASSPATH="$HOME/java:."
    export CLASSPATH
    Now you need to apply the changes: . /etc/profile
  8. Verify your installation: java -version Also try writing a little Hello World program and running it from different directories.
Explanation
When you use the “java” command, the operating system will use the first instance it comes across — in my case, GCJ’s.
Resources
Original solution: Debian Manual has more detail and explanation, but less step-by-step instructions. It also has some post-installation tips.

Responses: 4 so far Feed icon

  1. Ryan Ruiz says:

    Excellent instructions. Much apprciated!! Thanks. Great info on building a .deb package.

  2. MEEPr » GCJ Makes Babies Cry says:

    [...] So, after scouring the web for sometime, I found this blog post that describes a good way to install the JRE on ubuntu. http://www.brainonfire.net/blog/solutions/?p=6 [...]

  3. Hasan says:

    Hi, I was following ur instructions above, but got the following problem with step 3. Any help will be greatly appreciated. Thanks!

    alhasan@alhasan-laptop:~/temp$ fakeroot make-jpkg jdk-6-linux-i586.bin Creating temporary directory: /tmp/make-jpkg.XXXXRqzfmE Loading plugins: blackdown-j2re.sh blackdown-j2sdk.sh common.sh ibm-j2re.sh ibm-j2sdk.sh j2re.sh j2sdk-doc.sh j2sdk.sh j2se.sh sun-j2re.sh sun-j2sdk-doc.sh sun-j2sdk.sh

    No matching plugin was found. Removing temporary directory: done alhasan@alhasan-laptop:~/temp$

  4. Tim McCormack says:

    It looks like you might need the development version of java-package (in the feisty repository), as I found in the Ubuntu forums.

Commenting is not yet reimplemented after the Wordpress migration, sorry! For now, you can email me and I can manually add comments.