Java in Ubuntu

Well, I am now just trying to use Ubuntu as a development environment. First thing I noticed is that there are more than one jre already installed by default in the system, and here is the evidence:


jars@jars-desktop:~$ locate /rt.jar
/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar
/usr/lib/jvm/java-6-sun-1.6.0.07/jre/lib/rt.jar

I really wanted to use the Sun JDK for my development instead of OpenJDK, so I installed the Sun Java.

Just type the command below and compare the results:

sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk sun-java6-source sun-java6-plugin jdk-6u10-docs.zip jdk-6u10-docs-ja.zip

But which of the two JVMs that now reside in my system area going to be used? Here it comes the ass-saving (and brand new to me) Ubuntu command:


sudo update-java-alternatives -s java-6-sun

This will define Sun Java-6 as the default JVM in your system. If you prefer to do it step-by-step just type this:


jars@jars-desktop:~$ sudo update-alternatives --config java

There are 2 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
+ 1 /usr/lib/jvm/java-6-openjdk/jre/bin/java
* 2 /usr/lib/jvm/java-6-sun/jre/bin/java

Press enter to keep the default[*], or type selection number:

The next tricky step is to set the prefered order in which your JVMs shoud be used. To set this up just edit the /etc/jvm file and include your recently installed JVM as the first one, so your file looks more or less like this:


# This file defines the default system JVM search order. Each
# JVM should list their JAVA_HOME compatible directory in this file.
# The default system JVM is the first one available from top to
# bottom.

/usr/lib/jvm/java-6-sun
/usr/lib/jvm/java-gcj
/usr/lib/jvm/ia32-java-1.5.0-sun
/usr/lib/jvm/java-1.5.0-sun
/usr

Ok, not ready yet, but I am not willing to return to Windows without doing this until the end! :)
So, next step is setup the environment variables and if you want to set it system wide, edit the /etc/profile file and append the following lines at the end:


export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

You can also set the variables for only one user by editing /home/$user_name$/profile.

Now test it!!


jars@jars-desktop:/etc/alternatives$ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options