This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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
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.
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 ]
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).
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: