Book Image

OpenJDK Cookbook

Book Image

OpenJDK Cookbook

Overview of this book

Table of Contents (20 chapters)
OpenJDK Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Installing OpenJDK on Linux


The Linux operating system allows for many internal tweaks, as well as for changes to the system's source code. It is also known as a complicated OS, and not all distributions are user-friendly. There are many people using it, and it's open source, such as OpenJDK itself. The installation process varies between chosen distributions, and we will go through the process for the three most-used package managers, as well as through the process that will work for virtually all x86 Linux distributions.

Getting ready

To follow this recipe, you will need an installed Linux system. It will be better if it has the kernel version 2.6 or higher, though OpenJDK is reported workable on 2.4 kernels as well. Also, if you have the .deb, .rpm, or .ebuild package manager, the recommended way to install any package is to install it using those.

How to do it...

When the installation of various packages is concerned, the process is dependent on our Linux distribution.

For a Debian-based distribution:

  1. Open a terminal and type:

    apt-get install openjdk-7-jdk

    Tip

    We should have root permissions or use sudo to gain access to system files.

  2. This will trigger the installation automatically. If we get an error message, indicating that the package is not found, we should Google an appropriate name for an OpenJDK package for our distribution.

For an RPM-based distribution, we'll need to first search for the package names, because package names are varied between different distributions, as shown here:

yum search openjdk

You will see an output like this:

java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle

You may install all of the packages that have the desired version. Then, we will run another command, using the package name we've just found:

yum install <a found package name>

This will also trigger an automatic download and installation.

If we have a Gentoo-based distribution, just type the following:

emerge openjdk-1.7

This will, depending on your distribution, unpack and install a binary package or, more probably, automatically build this package from source.

There's more...

Aside from the recommended ways, there is a generic installation procedure. It is quite simple, though it may do some damage to your operating system, so don't use it unless you really know what you're doing:

  1. This is the way to unpack the OpenJDK system and then install it yourself. To get the builds, we will refer again to the unofficial build page, https://github.com/alexkasko/openjdk-unofficial-builds.

  2. Then unpack the downloaded package into a folder and run the following command from it:

    java -jar ./install.jar
  3. A GUI installer window will appear. Read and accept the license, choose the directory, and allow OpenJDK to be created, if it does not exist, as shown:

  4. Check the preceding checkbox if you want to make this installation the default one. Then click on the Next button.

  5. Wait for the installation to complete, and click on Next for the last time.

  6. Then click on Done.