Installing Sun Java on Linux

  • October 17, 2007
  • Avatar for peter
    Peter
    Upfold

Java logo While Sun's Java platform is now almost completely open source, most distributions haven't been updated to ship with the technology (and there is a small amount of code that still isn't open source). Without Java, you could be missing out on running some applications and (less frequently now) Java applets on websites.

It is a little bit of a pain to install however, so in this tutorial I'll be showing you how to install it from Sun's website using the self-extracting installer.

So first of all, let's head on over to the site and go to the Linux Java downloads page. Let's jump there quickly however, so click on the following link - http://www.java.com/en/download/linux_manual.jsp?locale=en&host=www.java.com:80.

On that page, we want the self-extracting file (and for wide compatibility, I'm not doing the RPM version in this tutorial, so choose the one below that). Let that file download. Now we'll need to head over to the terminal for a bit (I'll assume that file you downloaded is on your desktop).

I'm going to install Java into the /usr/java folder, which doesn't exist yet, so we need to login as root and create it. If you're on Ubuntu, ignore all su - commands, but remember any time you see the hash # symbol in front of a command, you'll need to prefix it with sudo. Most other distros can follow this as is:

$ su -
# mkdir /usr/java
# chmod u=rwx,g=rx,o=rx /usr/java

Now we need to copy the self-extracting installer to this new directory. In the following command, you'll need to substitute in your own username, and the exact name of the downloaded file.
# cp /home/peter/Desktop/jre-6u3-linux-i586.bin /usr/java
# cd /usr/java

One more step before we launch the installer; we need to set the permissions on it so we are allowed to execute it.
# chmod a+x jre-6u3-linux-i586.bin
# ./jre-6u3-linux-i586.bin

You'll see the licence agreement - use space to page through. Once you get to the bottom you'll be asked to type 'yes' to accept, which you have to do in order to continue.

The self-extractor will then get to work and unpack Java. Once that's done, you do have a working installation, but there are a couple of things to set up in your user for Java to 'just work' when launching Java programs.

Open up the file called .bashrc in your home folder (or the equivalent if you're not running bash), and add these lines before saving:

export JAVA_HOME="/usr/java/jre1.6.0_03"
export PATH="${JAVA_HOME}/bin:${PATH}"

Finally, to get the browser plugin working on Firefox and similar browsers, you should be able to just copy the plugin file in place like this:
# cp ${JAVA_HOME}/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla/plugins

Phew! After that you should have a running Java installation.

Avatar for peter Peter Upfold

Home » Articles »