Jump to content

How to Install Java in Ubuntu

+ 3
  greenfly's Photo
Posted Oct 24 2009 07:15 PM

The modern web-browsing experience requires Java. Here's how to install Java and caffeinate your web browser.

Ubuntu's an amazing Linux distribution for lots of different reasons, but one of the things people find attractive about it is the fact that it ships with lots of different software, preconfigured and ready to use. However, until recently, one of the things that the Ubuntu developers couldn't include was the Sun Java Runtime Environment (JRE), because it used a nonfree license that prevented its bundling with a Linux distribution.

Recently, however, Sun Microsystems relaxed the restrictions on the Java license, introducing the Distro License for Java (DLJ). This new license allows distributors to ship Sun's JRE and Java Development Kit (JDK) as installable packages, rather than the self-extracting binaries that were previously available. It also gives Linux distributors the ability to define the packaging, installation, and support for Java within their Linux distribution.

As such, Dapper Drake now ships with Sun's Java available as a non-free package in the multiverse repository. You'll need to have the universe and multiverse repositories enabled to install Java.

The Ubuntu developers have separated the Java components into several packages:


Contains the binaries


Contains demos and examples


Contains the documentation


Contains the Lucida TrueType fonts from the JRE


Contains the metapackage for the JDK


Contains the metapackage for the JRE


Contains the plug-in for Mozilla-based browsers


Contains source files for the JDK

Installing the Java Runtime Environment

Once you've got the multiverse repository enabled, installing Sun's Java package is easy. Simply open a terminal window and apt-get the package. Since you are going to be installing the JRE and the web browser plug-in, you'll be using the following command from a terminal window:

bill@constellation:~$ sudo apt-get install sun-java5-jre sun-java5-plugin \\


Once apt-get downloads the packages and begins the installation, you'll get a screen that contains the Sun Operating System Distributor License for Java. Read the license, if you wish, and hit Enter to continue. You'll see a dialog that asks you if you agree with the DLJ license terms. Select Yes, and hit Enter; the JRE will finish installing.

At this point, Java is installed.

Confirming the Installation

You'll want to confirm that your system is configured properly for Sun's JRE. This is a two-step process. First, check that the JRE is properly installed by running the following command from a terminal. You should get similar output:

bill@constellation:~$ java -version

java version "1.5.0_06"

Java™ 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)

Java HotSpot™ Client VM (build 1.5.0_06-b05, mixed mode, sharing)


If you see an unexpected version of Java—in particular, one identified as "gij (GNU libgcj)"—then you probably have GNU Java installed. You can easily switch from one Java to another with the command sudo update-alternatives --config java, which will prompt you to choose which Java implementation to use. Pick the one in /usr/lib/jvm to use the JRE you just installed.

If the JRE is properly installed, confirm that the Java plug-in is installed in your browser by opening Firefox and typing about:plugins in the address bar (see Figure 1).

Figure 1. Verifying that the Java web plug-in is installed

Attached Image

Congratulations, you've caffeinated your browser! You can now surf to Java-enabled web sites and use Java applications!

Ubuntu Hacks

Learn more about this topic from Ubuntu Hacks.

Like all books in the "Hacks" series, Ubuntu Hacks includes 100 quick tips and tricks for all users of all technical levels. Beginners will appreciate the installation advice and tips on getting the most out of the free applications packaged with the Ubuntu Linux distribution, while intermediate and advanced readers will learn the ins-and-outs of power management, wireless roaming, 3D video acceleration, server configuration, and much more.

See what you'll learn

0 Subscribe

2 Replies

 : Nov 05 2009 01:11 AM
J2SE 5.0 reached its End of Service Life (EOSL) on November 3, 2009, which is the date of the final publicly available update of version 5.0 (J2SE 5.0 Update 22).
 : Nov 05 2009 01:58 AM
Simple user install:
  • You have to know how to install packages with Synaptic, Aptitude, apt-get or others tools. You will be prompted for a license. You have to accept: type yes or clic OK depending on the interface. Warning do not use KPackage since it isn't possible to accept the license. It fails silently. (Will find the reference to this bug.)
  • Since there is not "one" Java package, you will have to install:
    • sun-java6-jre for desktop applications
    • sun-java6-plugin for Web application (plugin for the browser)

Developers will want to install sun-java6-jdk, sun-java6-doc, sun-java6-source.

Some application may require an environment variable: JAVA_HOME or JDK_HOME or both. You can set them up in you ~.bashrc or in /etc/profile.d/java.sh. (The JDK and JRE are in /usr/lib/jvm).

You can have multiple Java installations. Sun's JavaVM, IBM's JavaVM, IcedTea ...
  • For a simple user it may be just an annoyance: remove all packages related to java and not starting with "sun-java6".
  • For advanced users: man update-java-alternatives.