Monday, May 18, 2009

Install Java on Ubuntu


There are so many guides to install Java 6 manually on the Ubuntu
forums that I kinda got lost between them all (but I did get Java 6
working). I'm writing this guide in order to make it simple to install
and easy to understand (through the shell script).

Note: There are 2 ways to install java6 nowadays b/c java6 has been added to the repositories (multiverse)

The following method is if you have the multiverse repository
enabled/added to your /etc/apt/sources.list (I won't go covering how to
do that here)

To install:

sudo apt-get update

# To install the mozilla plugin remove the # on the next line

sudo apt-get install sun-java6-jdk #sun-java6-plugin

update-java-alternatives --list

# The line above should produce output somewhat similar to:

# java-6-sun 63 /usr/lib/jvm/java-6-sun

# Add the first part of the line above to the end of the next line

sudo update-java-alternatives --set java-6-sun

Now if you want to change java versions just do:

update-java-alternatives --list

sudo update-java-alternatives --set <one of the java versions>


The following method shows how to install java 6 manually (in case you
don't want multiverse repo. enabled for security reasons or if you just
want to learn how to do it)

1. Download the Java 6 SDK (Make sure you download the "Linux
self-extracting file") from

2. After it has finished downloading you will have a file called jdk-6-linux-i586.bin

3. Run the following in the directory that the file is located in (Change any variables as you see fit)




chmod +x $JDKFILE



# Uncomment the following line to have Mozilla browsers (i.e. Firefox) load the Java 6 plugin

# ln -s $JDKPATH/$JDKFOLDER/jre/plugin/i386/ns7/ ~/.mozilla/plugins

echo "export JAVA_HOME=$JDKPATH/$JDKFOLDER" >> ~/.bashrc

echo "PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH" >> ~/.bashrc

source ~/.bashrc

Now you can test to see if java 6 is installed by running: `java -version` and `javac -version`

This should print out something similar to:

joncfoo@A3200:~$ java -version

java version "1.6.0"

Java(TM) SE Runtime Environment (build 1.6.0-b105)

Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

joncfoo@A3200:~$ javac -version

javac 1.6.0

Now if you have other versions of Java installed and want to use them,
the easiest way to do is would be to change the JAVA_HOME variable by

export JAVA_HOME=/another/java/directory

After you have done this, just launch whatever application(s) you need under that version of Java

I hope this is straightforward and to the point. If not feel free to ask me any questions.

No comments:

Post a Comment