Ubuntu: Setting up Oracle JDK

Since Oracle’s Java SDK is not part of Ubuntu, there are some steps required to get Java set up on a Ubuntu system. Especially running a 64-bit version of Ubuntu requires one tiny additional step driving you crazy in case do not speak Ubuntu fluently.

There are quite some scripts and tutorials out there how to get Oracle’s Java working on a Ubuntu system, however, there are only a few steps necessary to do so:

Pick the bits from Oracle’s download site and extract the archive using tar. In my case we use the 32-bit version of the JDK

tar -xvf ~/Downloads/jdk-7u15-linux-i586.tar.g

Create a folder and move all the stuff over there

sudo mkdir -p /usr/lib/jvm/jdk1.7.0 
sudo mv jdk1.7.0_15/* /usr/lib/jvm/jdk1.7.0/

Now set up the symbolic links for java, javac and javaws.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1

Now, create a Bourne script to set the JAVA_HOME variable and update the PATH variable. In case you haven’t used Vim yet, get it using

sudo apt-get install vim

and then create the file

sudo vim /etc/profile.d/java7.sh

edit the file file and add the following export statements

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0
export PATH=$PATH:$JAVA_HOME/bin

Finally execute the script

source /etc/profile

and try to call java. If you run a freshly set up Ubuntu such as mine, you probably will end up the system telling you

bash: /usr/bin/java: No such file or directory

What happened? Actually, we installed a 32-bit version of the JDK, however as mentioned at the beginning running a 64-bit version of Ubuntu and therefore we come back to this very tiny bit missing. One additional package is required to run the 32-bit version: libc6-i386.

“This package includes shared versions of the standard C library and the standard math library, as well as many others. This is the 32bit version of the library, meant for AMD64 systems.”

Said that, get it

sudo apt-get install libc6-i386

and try to run java one more time. It should work now fine.

1 Comments

  1. Michael

    Reply

    Artikel von Dir über Ubuntu und Java? In welchem Paralleluniversum bin ich denn heute morgen aufgewacht?
    😉

Leave Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.