Introduction
Java is a technology from Oracle (formerly: Sun Microsystems). There are several implementations, of which five will be discussed here:
OpenJDK: The primary goal of the OpenJDK project is to produce an open-source implementation of the Java SE Platform (6 and 7). This is the default version of Java that Ubuntu uses and is the easiest to install.
Oracle (Sun) Java 6: Oracle (Sun) Java 6 is the reference implementation for Java 6.
Oracle Java 7: Oracle Java 7 is the reference implementation for Java 7.
IBM Java: IBM Java is the preferred Java solution on PowerPC machines. It is a reimplementation with a Just-In-Time Compiler. It is only available from IBM's website.
GNU Compiler: A Java compiler made by GNU. Only developers should have to install this.
OpenJDK
Installation of Java Runtime Environment
Install the openjdk-6-jre package using any installation method.
Install the openjdk-7-jre package using any installation method.
Browser plugin
Install the icedtea6-plugin package using any installation method.
Install the icedtea7-plugin package using any installation method.
This plugin works with the main browsers: Firefox, Chromium, Google Chrome, and Epiphany.
On Konqueror, go to Settings → Configure Konqueror... and from menu select Java & JavaScript, then tick Enable Java globally option.
SDK (Software Development Kit)
Install the openjdk-6-jdk package using any installation method.
Install the openjdk-7-jdk package using any installation method.
Oracle (Sun) Java 6
Oracle (Sun) Java 6 is no longer available to be distributed by Ubuntu, because of license issues.
Important note: Oracle (Sun) Java 6 reaches its End of Life in November, 2012. It is not advisable to install Oracle (Sun) Java 6 unless you have some specific need to do so.
It is recommended that users either migrate to OpenJDK, or switch to Oracle Java 7. Older versions of Oracle (Sun) Java 6 that have been distributed in the past are vulnerable to security exploits, see this announcement for more information.
Probably outdated information about the installation of Oracle Java 6:
JDK or JRE
Downloads the Java binary installers from Oracle, builds the .deb packages locally on your computer and then installs them. Packages are compatible with the “official” Ubuntu ones and will upgrade Java 6 that was previously installed from packages.
You can find the script and full usage instructions on github.
Manual method
- oracle java 6 jre 32-bit
$ wget http://download.oracle.com/otn-pub/java/jdk/6u31-b04/jre-6u31-linux-i586.bin $ chmod u+x jre-6u31-linux-i586.bin $ ./jre-6u31-linux-i586.bin $ sudo mv jre1.6.0_31 /usr/lib/jvm/ $ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.6.0_31/bin/java" 1 $ sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/usr/lib/jvm/jre1.6.0_31/lib/i386/libnpjp2.so" 1
or
- oracle java 6 jdk 32-bit
$ wget http://download.oracle.com/otn-pub/java/jdk/6u31-b04/jdk-6u31-linux-i586.bin $ chmod u+x jdk-6u31-linux-i586.bin $ ./jdk-6u31-linux-i586.bin $ sudo mv jdk1.6.0_31 /usr/lib/jvm/ $ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_31/bin/java" 1 $ sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/usr/lib/jvm/jdk1.6.0_31/jre/lib/i386/libnpjp2.so" 1
IMPORTANT choose the java you installed as default
$ sudo update-alternatives --config java $ sudo update-alternatives --config mozilla-javaplugin.so
Oracle Java 7
Oracle has recently declared Java 7 to be fit for general use.
Currently there are no .deb packages available for Oracle Java 7. The raw binaries (without installer) can be downloaded directly from Oracle (Oracle Java download page).
Installing Oracle Java 7 by a script or from the command line
You can install the newest and secure Oracle (Sun) Java 7 by a script (JRE only) or by a command line method. Both are easy to apply.
Script (JRE only)
Only supports Oracle (Sun) Java 7 JRE (which covers the needs of 99 % of all computer users). It pulls the packages from Oracle's website and installs them, comparable to the way Adobe Flash Player is being installed. Plus it adds a dedicated repository, from which you'll receive updates automatically.
Command line methods
Do-it-yourself methods, but very easy to apply (basically: you copy/paste some terminal commands).
http://sites.google.com/site/easylinuxtipsproject/java (for JRE, more extensive explanation of the commands than in askubuntu.com)
- You may also install Oracle Java 7 using PPAs from either webupd8 or Eugene San. The PPAs do not contain the Oracle files themselves, but contain scripts that will download and install Oracle Java 7 and install the Oracle Java 7 browser plugin.
Choose one PPA or the other by entering one of the following in the terminal:
$ sudo add-apt-repository ppa:webupd8team/java
or
$ sudo add-apt-repository ppa:eugenesan/java
Then, install the package thus:
$ sudo apt-get update $ sudo apt-get install oracle-java7-installer
To remove Oracle Java 7, simply do the following:
$ sudo apt-get remove oracle-java7-installer
There is also an RFE opened on Oracle bugtracker to provide the debian package/installer for Java 7. Please consider voting for this RFE.
Choosing the default Java to use
If your system has more than one version of Java, configure which one your system uses be entering the following command in a terminal window
sudo update-alternatives --config java
IBM Java (PowerPC)
IBM Java is the preferred Java version on the PowerPC architecture (OpenJDK is available on PowerPC, but it is rather slow.) IBM produces a Java Development Kit (JDK) for its POWER computers, which happens to also work on PPC. The recent versions of IBM's Java are versions 1.5.0 (version 5) and 1.4.2 (version 4) of Java.
The 1.4.2 JDK is known to work on G3, G4, and G5 Macs, as well as older 604e and 603e Macs. The 1.5.0 JDK is known to work on G3, G4, and G5 Macs, and it is not yet known whether it works on older 604e and 603e Macs. Both also work on non-Mac PowerPCs like the EFIKA. Please update this page if you have more information!
The easiest way is to add the medibuntu-repository to your sources.list.
sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update
After that, you can install the 'ibm-j2sdk1.5' package using any installation method.
Another way to install IBM Java is to go to the IBM WebSphere Application Server Community Edition from SourceForge for both x86 and PowerPC -http://sourceforge.net/powerbar/websphere/download.php.
To use the TGZ with Ubuntu, you have to convert it to a DEB. Make sure you have the tool make-jpkg installed.
cd ~/Desktop sudo dpkg -i java-package_0.27_all.deb
Now convert the 1.4.2 TGZ and install the resulting DEB:
make-jpkg IBMJava2-SDK-142.ppc.tgz sudo dpkg -i ibm-j2sdk1.4_1.4.2_powerpc.deb
Now convert the 1.5.0 TGZ and install the resulting DEB:
make-jpkg ibm-java2-sdk-50-linux-ppc.tgz sudo dpkg -i ibm-j2sdk1.5_1.5.0_powerpc.deb
Note: The latest version (as of February 1, 2007) of the IBM 1.5 SDK, SR4, is called ibm-java2-sdk-5.0-4.0-linux-ppc.tgz. When I tried to install it on Edgy, it returned a No matching plugin found. error. I was able to install it successfully by renaming the downloaded file to match the name ibm-java2-sdk-50-linux-ppc.tgz before running the make-jpkg command.
Note on libraries: the IBM Java binaries depend on libstdc++5 and libgtk1.2 packages. In Dapper and later it's possible that these libraries are not installed because they've been replaced by libstdc++6 and libgtk2.0. In this case, make-jpkg will give a lot of warnings about not being able to find dependencies for library files. To get the dependencies set correctly (and to get the Java to work at all), make sure you have installed libstdc++5 and libgtk1.2 (either by using Synaptic or from the command line) before issuing the make-jpkg command.
To set the new JRE or JDK as the default, you may need to update your Java alternatives. To check your current default, run:
java -version
If you're not happy with what you see, run the following command and, when prompted, choose your preferred Java environment from the list. If update-alternatives tells you that there is only one Java environment, then you'll need to install another version to make a change. If you chose to install both 1.4.2 and 1.5.0 versions, you may run this command at any time to switch the one subsequently opened Java applications will use. The one that the Firefox and Opera web browsers use will be unaffected. Which one the Konqueror web browser uses, and whether or not it would be affected, depends on your KDE system settings.
sudo update-alternatives --config java
If you installed a 1.4.2 version, regardless of whether or not you installed a 1.5.0 version, and your processor is not a G5, you must perform yet another step to get it to work. For a G3 or G4, use the following command:
sudo sh -c 'echo "JITC_PROCESSOR_TYPE=6" >> /etc/environment'
For a 604e or 603e, instead use:
sudo sh -c 'echo "JITC_PROCESSOR_TYPE=5" >> /etc/environment'
You may have to log out or restart the computer for this to take effect.
Note: In the GNOME environment of Ubuntu 6.06 LTS/Dapper Drake, it may be possible that changing language selections may overwrite this file, causing a 1.4.2 version of IBM Java to stop working completely. Please share such experiences, if any, on this wiki.
IF you installed the JDK, the following code tests that everything's working. Open a terminal, and try this for version 1.4.2:
cd /usr/lib/j2sdk1.4-ibm/demo/applets/TicTacToe ../../../bin/appletviewer example1.html
To try version 1.5.0:
cd /usr/lib/j2sdk1.5-ibm/demo/applets/TicTacToe ../../../bin/appletviewer example1.html
If you see a Tic Tac Toe game, it worked! If you installed the JRE, you don't have an appletviewer or any demos so try whichever program it was that led you to install java in the first place!
Neither the Firefox web browser nor the full Mozilla suite can use version 1.4.2, but they can use 1.5.0 if you configure as follows:
mkdir -p ~/.mozilla/plugins cd ~/.mozilla/plugins ln -s /usr/lib/j2sdk1.5-ibm/jre/bin/libjavaplugin_oji.so
To control which Java the Konqueror web browser uses, go to your KDE system settings. Select Internet & Network -> Web Browser -> Java & JavaScript, and change the Path to Java executable to either /usr/lib/j2sdk1.4-ibm/bin/java or /usr/lib/j2sdk1.5-ibm/bin/java.
To control which Java the Opera web browser uses, go to Tools -> Preferences -> Advanced -> Content -> Java options, and change the path to either /usr/lib/j2sdk1.4-ibm/jre/bin or /usr/lib/j2sdk1.5-ibm/jre/bin.
Test the installation at the Sun Java test webpage.
GNU Compiler for Java
Install the java-gcj-compat-headless package using any installation method.
To install the development environment, install the java-gcj-compat-dev package using any installation method.
GCJ is a front end to the GCC compiler which can natively compile both Java(tm) source and bytecode files. The compiler can also generate class files. Gcjwebplugin is a little web browser plugin to execute Java applets.
It is targeted for Mozilla and compatible browsers that support the NPAPI. Others include the Eclipse Java Compiler, which is maintained by the Eclipse Foundation. Eclipse is an open-source Integrated development environment (IDE) written primarily in Java. The Eclipse open source community has over 60 open source projects. OpenJDK is the open source Java, derived from sources which will become OpenJDK 7 in the future.