Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to install JDK6 on Ubuntu?

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:

sudo update-alternatives --config java


I didn't know about that. Cool! Thanks Jesper.
 
Diego Freniche
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic