This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes How to install JDK6 on Ubuntu? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to install JDK6 on Ubuntu?" Watch "How to install JDK6 on Ubuntu?" New topic
Author

How to install JDK6 on Ubuntu?

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Hi.
I got the JDK6 from Java's site and I'm wondering to install it.
I have to create an environment variable too, right?
Thanks.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

the easiest way is via Synaptic, install sun-java6-jdk

Otherwise you should follow the instructions on the Sun site, which involves making the binary executable then running it

chmod +x (file)
./(file)
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

There are probably several ways to do this. Here is how I do it.

Download the Linux .bin file from Sun's site.
chmod +x xxx.bin
./xxx.bin
Accept license.
mv jdk1.6.x_x wherever you want

vim .bashrc
export JAVA_HOME=/where/you/put/the/jdk
export PATH=$JAVA_HOME/bin:$PATH
:qw

Done!

I usually install all the JDK's in a dev folder under my home location. JAVA_HOME typically points to the most recent version for general java applications that run. When doing development I always point my build/IDE to a specific version aside from JAVA_HOME.


GenRocket - Experts at Building Test Data
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The newest version of Java 6 (version 1.6.0 update 3) is in the Ubuntu 7.10 repositories. Installing software from the repositories is the preferred way on Ubuntu.

You can install sun-java6-jdk and sun-java6-plugin (the browser plug-in, to run applets) from Synaptic or by typing in the following command:

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

Note that Ubuntu by default comes with GNU Java, which is a slow and incomplete (but 100% open source) version of Java 1.4. After installing Sun Java 6, you might need to make it the default Java used on your system with the following command:

sudo update-alternatives --config java

Select Sun Java 6 in the menu that appears.

You do not need to create any environment variables.
[ January 04, 2008: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Jesper Young:

sudo update-alternatives --config java


I didn't know about that. Cool! Thanks Jesper.
Diego Freniche
Greenhorn

Joined: Dec 28, 2007
Posts: 8
Originally posted by Gregg Bolinger:


I didn't know about that. Cool! Thanks Jesper.


If you want to have a look under the hood, try:

You can change a symbolic link by hand :-)

I always install various JDKs in /opt. Later, I use different environment variables (or configs inside Eclipse) to point to one JDK or another.


SCBCD 1.3, SCWCD 1.5, SCJP 1.5 & 1.6
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Thank you all guys.
I used Synaptic as Mr. Jesper suggested and it works.
By using Synaptic to get JDK6, should I create JAVA_HOME environment variable by hand or Synaptic get it done?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Originally posted by John Todd:
should I create JAVA_HOME environment variable by hand or Synaptic get it done?
What happens if you type echo $JAVA_HOME ?


OCUP UML fundamental and ITIL foundation
youtube channel
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

I don't think that by installing it via Synaptic a JAVA_HOME environment variable will be set up. As Jan says, you can check if it is set with echo $JAVA_HOME.

You don't really need a JAVA_HOME or any other environment variable for Java to work. Some programs, like Tomcat, use this variable to determine where the JVM is on Windows (I'm not sure if the Linux version of Tomcat needs this too).
Rohan Dhruva
Ranch Hand

Joined: May 08, 2007
Posts: 183
I have a little to add to Jesper's detailed post-
To set ALL the java related symlink automatically to the Sun version of Java (e.g. apt, servtool, jar, javap etc.) do this:

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

Also, please DO NOT use the official Sun tarballs to install JDK - that way the JDK is not registered with the package manager and alternatives system, and more often than not the firefox plugin won't work either.

Incidentally, the JAVA_HOME variable is not set by the package manager, because it is assumed that all java software will be installed using the package manager, and that doesn't need JAVA_HOME variable set.
This is not always the case, for example I had to install maven manually, which requires that variable. Hence I have added this line to by ~/.bashrc file:

[ -d /usr/lib/jvm/java-6-sun-1.6.0.03 ] && export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.03

Hope that helps
[ January 07, 2008: Message edited by: Rohan Dhruva ]

Rohan B. Dhruva
SCJP 1.5
 
jQuery in Action, 2nd edition
 
subject: How to install JDK6 on Ubuntu?
 
Similar Threads
JDK 6 and JavaDB or Apache Derby... How do I install?
setProperty must be overridden by all subclasses of SOAPMessage when using Eclipse and JBoss
Where to find javax.servlet.jsp package?
diff. in jdk5 and jdk6 software
java compiler version