ContentsBRTableOfContents |
Be aware of the [http://www.gnu.org/philosophy/java-trap.html Java trap]. Although keep in mind that with the GPL licensing of the Sun Java implementation the Java trap is a thing of the past. Even RMS thinks so. Use IcedTea on Ubuntu 7.10 and OpenJDK on Ubuntu 8.04 or later.
The first free project to offer substantial parts of Java platform functionality was [http://www.ccs.neu.edu/research/demeter/course/f96/hw/1/guavac-info Guavac]. After that the free software movement developed java compilers, most notably the [http://gcc.gnu.org/java/ GNU Compiler for Java]. 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. [http://www.nongnu.org/gcjwebplugin/ 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 [http://www.eclipse.org/home/newcomers.php 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.
Prerequisites
To install OpenJDK, you must have the Universe repository enabled and be running Ubuntu 8.04 or later.
To install proprietary Java, you must have the Multiverse repository enabled. Keep in mind that this repository is different from the backports Multiverse repository. That is, do not simply uncomment the "multiverse" line for backports. Instead, you will need to add "multiverse" to the existing main line in /etc/apt/sources.list.
To install IcedTea, you must have the Universe repository enabled and be running Ubuntu 7.10 or later.
For more information about the Multiverse and Universe repositories, please visit the following guide:
[:Repositories:Managing Repositories].
Introduction
Java is a technology from Sun Microsystems. There are several implementations, of which five will be talked about here:
OpenJDK: The primary goal of the OpenJDK project is to produce an open-source implementation of the Java SE 6 Platform. As of Ubuntu 8.04, it is located in the universe repository.
Free Java: GNU classpath and others, these are already included in Ubuntu as of Ubuntu 5.10. These implementations are available for all supported Ubuntu architectures.
IcedTea: IcedTea is a build of OpenJDK from Red Hat that is composed of free software. As of Ubuntu 7.10, it is located in the universe repository.
Sun Java: Sun Java is the reference implementation. As of Ubuntu 6.06, it is included in multiverse
Blackdown Java: Blackdown Java, a port of the Sun JDK to Linux which pre-dates Sun's official port, is included in multiverse of Ubuntu 5.10 and later
IBM Java: IBM Java is a reimplementation with a Just-In-Time Compiler. It is only available from IBM's website. It is the preferred Java solution on PowerPC machines, and instructions for Ubuntu on PowerPC are below. It is also available for i386 and AMD64, but use on such installations is not discussed here.
Java is also very different based on your processor architecture. Most computers are i386, Mac are PowerPC (although newer MacBooks and MacBook Pros are i386) and some newer computers are AMD64. Use the following chart to see which version of Java you should install:
Release |
|||||||||||
|
Free Java |
Proprietary Java |
|||||||||
|
8.04 |
7.04 |
6.10 |
6.06 |
7.04 |
6.10 |
6.06 |
||||
i386 |
OpenJDK or GCJ |
Sun Java |
|||||||||
PPC |
GCJ |
IBM Java |
|||||||||
AMD64 |
OpenJDK or GCJ |
Sun Java * |
|||||||||
SPARC |
GCJ |
- |
There is no browser plugin for the SPARC platform. On the AMD64 platform, the icedtea-gcjwebplugin is a browser plugin without LiveConnect support. For a more complete plugin, you will have to install a 32bit version of Firefox. See below.
Starting with Ubuntu 6.10 (EdgyEft), you can install the experimental java-gcj-compat-plugin from the universe archive. It is available on all architectures. Note however, that the plugin currently runs with no security manager. This means that applets you load can do anything a java application that you download and run can do. Be **very** careful which applets you run.
Installing OpenJDK
OpenJDK is available on Ubuntu 8.04 in the Universe repository. The runtime environment is located in the openjdk-6-jre package.
Installing GCJ
Free Java is already installed in the default installation java-gcj-compat. To install the development environment, install the java-gcj-compat-dev package.
Installing IcedTea
IcedTea is available on Ubuntu 7.10 in the Universe repository. The runtime environment is located in the icedtea-java7-jre package.
Installing Sun Java
Ubuntu 7.04 or later
Sun Java6: sun-java6-bin, sun-java6-jre
Blackdown Java2 1.4: j2re1.4
Ubuntu 6.06 / 6.10
Sun Java5: sun-java5-bin, sun-java5-jre
Blackdown Java2 1.4: j2re1.4
Kubuntu 6.06 / 6.10
- Sun Java5: Load up Konsole, and type:
sudo apt-get install sun-java5-bin
Accept the licence agreement that appears.
Note: The license may not come up and will cause the package installation to fail, to fix this, do the following:
- In a terminal, type
sudo apt-get install libqt-perl sudo dpkg-reconfigure debconf
- The first command will install the needed package for debconf-kde counterpart. The second command will ask a few questions: For the first step, choose "kde". For the second step, choose "high". Then, to fix the packages that did not correctly install, do:
sudo apt-get -f install
- then you are done.
Blackdown Java2 1.4: j2re1.4
Note: Scroll down to "Selecting the default Java version" section to enable the JRE you have installed.
Sun Java SDK (Software Development Kit)
Ubuntu 8.04
OpenJDK: openjdk-6-jdk
Ubuntu 7.10
IcedTea: icedtea-java7-jdk
Ubuntu 7.04
Sun Java6: sun-java6-jdk
Ubuntu 6.06 / 6.10
Sun Java5: sun-java5-jdk
Kubuntu 6.06 / 6.10
- Sun Java5: Load up Konsole, and type:
sudo apt-get install sun-java5-jdk
Accept the licence agreement that appears.
Blackdown Java2 1.4 packages: Install the j2re1.4 package, available in the multiverse repositories. Install it from the Applications -> Add/Remove... menu, or install the j2re1.4 package.
Selecting the default Java version
If you want to use Sun's Java instead of the open source GIJ (GNU Java bytecode interpreter) you need to set it as default. To list installed JVMs:
update-java-alternatives -l
To select, for example, Sun's JVM as provided in Ubuntu 6.06, run:
sudo update-java-alternatives -s java-1.5.0-sun
You should also edit /etc/jvm and move /usr/lib/jvm/java-1.5.0-sun to the top of JVMs offered.
Adding JDK 1.4 as an alternative
The Blackdown JDK 1.4 does not automatically appear as an alternative upon installation. In order to make it appear, you'll need to create a file such as /usr/lib/jvm/.java-1.4.2-sun.jinfo as described in the man page for update-java-alternatives. Note: the default install location is /usr/lib/j2se/1.4
Manual method: Run:
sudo update-alternatives --config java
and select your preference from the list.
Note: You probably want to do the same with jar, javac, javadoc, javah, javap and javaws:
sudo update-alternatives --config jar
To get common java applications (installed using .deb-packages) to run under your JVM of choice, make sure you also edit the JVM configuration file:
sudo nano /etc/jvm
and add the line:
/usr/lib/j2sdk1.5-sun
Packages such as ant starts the first JVM found in this file.
Java on Konqueror
You may find that Java is disabled, even though it is set up correctly in the "Configure Konqueror" Dialog. Select "HTML Settings->Java" from the Tools menu to enable it.
Java on Opera
Go to: "Tools"->"Preferences"->"Advanced"->"Content"-> check "Enable Java". to ensure it found Java click "Java Option" from the same dialog. the path should be something like "/usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/i386" for sun java
You can find the correct path using
$ locate libjava.so
or
$ find / -name libjava.so 2> /dev/null
Java on Mozilla Firefox
Ubuntu 8.04
OpenJDK: icedtea-gcjwebplugin
Ubuntu 7.10
IcedTea: icedtea-java7-plugin
Ubuntu 7.04
Sun Java6: sun-java6-plugin
Ubuntu/Kubuntu 6.06/6.10
Sun Java5: sun-java5-plugin
amd64: Installing the Mozilla/Firefox plugin
As of 2007-01-19, there is only one plugin that works and that is the one included with Blackdown Java 1.4.2 (see above for install instructions). Neither sun-java5-bin nor the recently released Sun Java 1.6 (Mustang), available from sun.com, contain a browser plugin for amd64.
To get later versions of Java working with Firefox on amd64, you need to install the 32-bit version of Firefox and run 32-bit Java 1.5 or 1.6. For a guide on how to do this please see ["AMD64/FirefoxAndPlugins"].
Note: The instructions below for creating a link for the plugin do not need to be carried out if running Ubuntu 6.06 or later amd64 with Blackdown Java and Firefox. But if for any reason you have problems with the plugin (cannot see it listed when navigating to about:config in Firefox) then create the link manually as described below...
Note: Manually modifying symlinks in your system may have unexpected results when installing new versions or upgrading. It is usually better to file a bug report (probably including a patch) to fix the problem at the source.
Method one:
$ sudo ln -sf /usr/local/j2re-1.4.2/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla-firefox/plugins/libjavaplugin.so
$ sudo ln -sf /usr/local/j2re-1.4.2/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin.so
Method two:
$ sudo ln -sf /usr/lib/j2re1.4-blackdown/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla-firefox/plugins/libjavaplugin.so
$ sudo ln -sf /usr/lib/j2re1.4-blackdown/plugin/amd64/mozilla/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin.so
PowerPC
OpenJDK is available on powerpc, in interpreted mode, which is rather slow.
IBM produces a Java Development Kit (JDK) for its POWER computers, which happens to also work on PPC. They are the only place to make available recent versions of Java for PPC Linux. Their recent versions consist of versions 1.5.0 and 1.4.2 of Java. They also have a 1.3.1 version, but there is no reason to use that. This page will not discuss the use of IBM's 1.3.1 version.
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 the Wiki if you have more information!
To get IBM's JDK, go to http://www-128.ibm.com/developerworks/java/jdk/linux/download.html, and choose an SDK for 32-bit iSeries/pSeries. Be sure to get the 32-bit version even if you have a G5. You may choose to download both the latest 1.5.0 and 1.4.2 versions and install both if you wish. In any case, periodically check that page for newer Service Releases, and repeat the process described here whenever there is a new one. There is currently no way to keep track of which Service Release you are on under Ubuntu, so make a note of it. As of this writing, SR4 is the latest of the 1.5.0, and SR7 is the latest of the 1.4.2 version. You will have to register before being allowed to download anything. When you reach the download page, download the TGZ version of the SDK.
Note: It appears that the IBM Java 5.0 JDK is available with IBM WebSphere Application Server Community Edition from SourceForge for both x86 and PowerPC - http://sourceforge.net/powerbar/websphere/download.php - the download does not require any registration.
Note: There is now an easier way to install the IBM JDK, all you have to do is to add the medibuntu-repository to your sources.list (or in a new file in the sources.list.d-directory if you are on Feisty) - simply replace "feisty" with the distribution you are using, e.g. "edgy" or "dapper":
echo "deb http://packages.medibuntu.org/ feisty free non-free" | sudo tee -a /etc/apt/sources.list
Then run this
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update
After that, you can use Synaptic, Adept or simply apt-get to install the package 'ibm-j2sdk1.5', latest version is still 1.5, no 1.6 yet - that may change with [http://openjdk.java.net/ OpenJDK]... The JDK will be set the new default by the install and Konqueror automatically detects it, but you may need to read the step regarding Firefox. You can skip the subsequent steps.
Installation Process
To use the TGZ with Ubuntu, you have to convert it to a DEB. Make sure you have the tool make-jpkg installed from the Multiverse repository (See ["AddingRepositoriesHowto"]):
sudo apt-get install java-package
If you are still using Breezy Badger, you will now need to upgrade the version of the package you just installed. To do this, download [http://archive.ubuntu.com/ubuntu/pool/multiverse/j/java-package/java-package_0.27_all.deb this file] to your desktop and type:
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 [http://www.java.com/en/download/help/testvm.xml test webpage].
javaws (Java web start) on 64-bit CPUs
If you have a 64-bit CPU and are having trouble with javaws not being found, see:
http://dmartin.org/weblog/running-java-web-start-apps-on-ubuntu-linux-for-amd-64
Apparently Sun's 64-bit Java doesn't include javaws, but you can install 32-bit java and use its javaws.
work-arounds
ppc: bug #343837
? ln -s /usr/lib/j2sdk1.5-ibm/jre/bin/libjavaplugin_oji.so /usr/lib/mozilla-firefox/plugins ?
Kubuntu 6.10
bug #69766
- Sun Java5
The instructions for 6.06 are still valid in Kubuntu 6.10. If you have attempted to install sun java packages using adept you may experience problems. Adept hangs at the point where it should display the license agreement. This is a bug in adept. If you press the 'show details' button the license agreement is visible in the background but OK cannot be selected. This is the work around: In a terminal type:
ps -e | grep adept
You should see output like this
4692 ? 00:00:08 adept_notifier 7228 ? 00:00:02 adept_manager
Type this command
sudo kill 7228
The number will be different each time. Then use the instructions for kubuntu 6.06 to install java from the commandline. it may be necessary to issue this command first
sudo dpkg --configure -a