Child pages
  • Open JDK
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 32 Next »

Table of Contents

Introduction

This page is based on experience of setting up Java 8 on Ubuntu 14.04.  Much of it may be applicable to other Java versions and distros.

Architecture

First we check which architecture we are running on.

Open a terminal and type the command :

arch

The output could be i686 or i386 for a 32 bits system or x86_64 for a 64 bits system.

Environment

Your environment could already have an installation or not.

Open a terminal and run the following command :

user@machine:~$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) Server VM (build 25.25-b02, mixed mode)

In the previous output we can see that the command has been successfully executed. It gives us the default version.

Then run the following command :

user@machine:~$ update-java-alternatives -l
java-1.6.0-openjdk-i386 1061 /usr/lib/jvm/java-1.6.0-openjdk-i386
java-1.7.0-openjdk-i386 1071 /usr/lib/jvm/java-1.7.0-openjdk-i386
java-1.8.0-openjdk-i386 1069 /usr/lib/jvm/java-1.8.0-openjdk-i386
java-8-openjdk-i386 1069 /usr/lib/jvm/java-8-openjdk-i386

The current installation shows that several JVM are installed.

Installation

Run the following commands in order to install or update the Open JDK 8. The idea is applicable to others JVM.

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk

Update Alternatives

if you have more than one Java versions installed on your system.

update-alternatives is a symbolic link management system for Linux.

Run the following command and select the desired jvm.

user@machine:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1071      manual mode
* 3            /usr/lib/jvm/java-8-openjdk-i386/jre/bin/java   1069      manual mode

Press enter to keep the current choice[*], or type selection number:

Set the default Java Compiler by running:

sudo update-alternatives --config javac

Set the default Java Web Start by running:

sudo update-alternatives --config javaws

In case your jvm is not recognized, you need to install it manually.

Run the following command:

sudo update-alternatives --install /usr/bin/java java /media/java-8-oracle 1071

Check if your added jvm has been processed by running:

user@machine:~$ update-alternatives --list java
/media/java-8-oracle
/usr/lib/jvm/java-8-openjdk-i386/jre/bin/java
/usr/lib/jvm/java-8-oracle/jre/bin/java

Manual installation need to be applied to each jdk components. In this tutorial we described the process for java, javac and javaws however more components need to be updated.

Follow the next paragraph before manually add everything, most of the time update-java-alternatives completes the work.

Update Java Alternatives

However this first part doesn't solve all the default tools to use with the desired JVM.

update-java-alternatives is a program to update alternatives for jre/jdk installations.

The following command shows you if the tools use the JVM you want :

user@machine:~$ update-alternatives --get-selections | grep java
appletviewer                manual   /usr/lib/jvm/java-8-openjdk-i386/bin/appletviewer
extcheck                      manual   /usr/lib/jvm/java-8-openjdk-i386/bin/extcheck
idlj                                manual   /usr/lib/jvm/java-8-openjdk-i386/bin/idlj
itweb-settings              auto     /usr/lib/jvm/java-6-openjdk-i386/jre/bin/itweb-settings
jar                                manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jar
jarsigner                      manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jarsigner
java                             manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/java
javac                           manual   /usr/lib/jvm/java-8-openjdk-i386/bin/javac
javadoc                       manual   /usr/lib/jvm/java-8-openjdk-i386/bin/javadoc
javah                           manual   /usr/lib/jvm/java-8-openjdk-i386/bin/javah
javap                           manual   /usr/lib/jvm/java-8-openjdk-i386/bin/javap
javaws                         auto     /usr/lib/jvm/java-6-openjdk-i386/jre/bin/javaws
jcmd                            manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jcmd
jconsole                       manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jconsole
jdb                               manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jdb
jdeps                           manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jdeps
jexec                           manual   /usr/lib/jvm/java-8-openjdk-i386/jre/lib/jexec
jhat                              manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jhat
jinfo                             manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jinfo
jjs                                manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/jjs
jmap                            manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jmap
jps                               manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jps
jrunscript                     manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jrunscript
jsadebugd                   manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jsadebugd
jstack                           manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jstack
jstat                             manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jstat
jstatd                           manual   /usr/lib/jvm/java-8-openjdk-i386/bin/jstatd
keytool                        manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/keytool
lucli                             auto     /usr/lib/liblucene2-java/lucli
mozilla-javaplugin.so  manual   /usr/lib/jvm/java-8-openjdk-i386/jre/lib/i386/IcedTeaPlugin.so
native2ascii                manual   /usr/lib/jvm/java-8-openjdk-i386/bin/native2ascii
orbd                           manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/orbd
pack200                     manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/pack200
policytool                    manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/policytool
rmic                            manual   /usr/lib/jvm/java-8-openjdk-i386/bin/rmic
rmid                            manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/rmid
rmiregistry                  manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/rmiregistry
schemagen                manual   /usr/lib/jvm/java-8-openjdk-i386/bin/schemagen
serialver                     manual   /usr/lib/jvm/java-8-openjdk-i386/bin/serialver
servertool                   manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/servertool
tnameserv                  manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/tnameserv
unpack200                 manual   /usr/lib/jvm/java-8-openjdk-i386/jre/bin/unpack200
wsgen                        manual   /usr/lib/jvm/java-8-openjdk-i386/bin/wsgen
wsimport                    manual   /usr/lib/jvm/java-8-openjdk-i386/bin/wsimport
xjc                              manual   /usr/lib/jvm/java-8-openjdk-i386/bin/xjc
user@machine:~

if the tools are not using the needed JVM some extra step are required:

Run the following command :

sudo update-java-alternatives -s java-8-openjdk-i386

This command update the dependencies but can also complain about some missing components.

update-alternatives: error: no alternatives for mozilla-javaplugin.so.
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-8-openjdk-i386/jre/lib/i386/IcedTeaPlugin.so

Verification

To verify is everything is fine you can check the if the correct program are used.

Run the following command :

which java javac javaws

You could have an output like this

/usr/bin/java
/usr/bin/javac
/usr/bin/javaws

We can continue with the following command :

file `which java javac javaws`

We could have an output like this :

/usr/bin/java: symbolic link to `/etc/alternatives/java' 
/usr/bin/javac: symbolic link to `/etc/alternatives/javac' 
/usr/bin/javaws: symbolic link to `/etc/alternatives/javaws'

and finally resolve the next symbolic link :

file /etc/alternatives/java /etc/alternatives/javac /etc/alternatives/javaws

and we got :

/etc/alternatives/java: symbolic link to `/usr/lib/jvm/java-8-oracle/jre/bin/java' 
/etc/alternatives/javac: symbolic link to `/usr/lib/jvm/java-8-oracle/bin/javac' 
/etc/alternatives/javaws: symbolic link to `/usr/lib/jvm/java-8-oracle/jre/bin/javaws'

In this sample all the links are going to the correct place.

This assumes the "alternatives" system is working properly, which might not be the case, depending on how Java has been "messed up" in the past.

Mozilla Java Plugin

In this example the Mozilla plugin is missing. This is not a big problem if you don't want to use for security reason.

In case you want to install it, here is the procedure to get it. At the time we wrote this guide the icedtea-8-plugin is not available in the standard repository.

sudo add-apt-repository ppa:maarten-fonville/ppa
sudo apt-get update
sudo apt-get install icedtea-8-plugin

As we installed a new java component we need to re-run the 'update-java-alternatives' command:

sudo update-java-alternatives -s java-8-openjdk-i386

Some problem can happen depending the sequence and the way you try to achieve this task. I face some issues with missing or wrong symbolic link.

Here is the output of my /usr/lib/jvm directory :

user@machine:~$ cd /usr/lib/jvm
user@machine:/usr/lib/jvm$ ls -al
total 88
drwxr-xr-x   6 root root  4096 Apr 19 15:39 .
drwxr-xr-x 210 root root 53248 Mar 31 07:41 ..
lrwxrwxrwx   1 root root    23 Apr 19 15:39 default-java -> java-1.8.0-openjdk-i386
lrwxrwxrwx   1 root root    19 Mar  5  2013 java-1.6.0-openjdk-i386 -> java-6-openjdk-i386
-rw-r--r--   1 root root  2345 Jan 26 23:05 .java-1.6.0-openjdk-i386.jinfo
lrwxrwxrwx   1 root root    19 Apr  8  2014 java-1.7.0-openjdk-i386 -> java-7-openjdk-i386
-rw-r--r--   1 root root  2396 Mar 24 16:46 .java-1.7.0-openjdk-i386.jinfo
lrwxrwxrwx   1 root root    19 Jan 29 06:25 java-1.8.0-openjdk-i386 -> java-8-openjdk-i386
-rw-r--r--   1 root root  2501 Jan 29 06:25 .java-1.8.0-openjdk-i386.jinfo
drwxr-xr-x   3 root root  4096 Mar 12  2013 java-6-openjdk-common
drwxr-xr-x   7 root root  4096 Feb 13 09:18 java-6-openjdk-i386
drwxr-xr-x   7 root root  4096 Mar 25 07:59 java-7-openjdk-i386
drwxr-xr-x   7 root root  4096 Apr 19 13:04 java-8-openjdk-i386
lrwxrwxrwx   1 root root    30 Apr 19 15:28 .java-8-openjdk-i386.jinfo -> .java-1.8.0-openjdk-i386.jinfo

The default-java should be linked with your desired JVM.

The command update-java-alternatives complained also with a missing .java-8-openjdk-i386.jinfo file. I created an appropriate link towards the existing .java-1.8.0-openjdk-i386.jinfo file.

Java Source

When I've installed the OpenJDK 8 I realized that the Java source code was not available. Usually below you default-java directory you should see a src.zip file. In my case the src.zip file was a reported broken link towards '../openjdk-8/src.zip'.

Run the following command :

sudo apt-get install openjdk-8-source

While installing a java component the command can give a few hints :

user@machine:~$ sudo apt-get install openjdk-8-source
[sudo] password for user:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-3.13.0-79 linux-headers-3.13.0-79-generic
  linux-image-3.13.0-79-generic linux-image-extra-3.13.0-79-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
Suggested packages:
  openjdk-8-demo visualvm openjdk-8-jre-jamvm fonts-ipafont-gothic
  fonts-ipafont-mincho ttf-telugu-fonts ttf-oriya-fonts ttf-kannada-fonts
  ttf-bengali-fonts
The following NEW packages will be installed:
  openjdk-8-jdk-headless openjdk-8-source
The following packages will be upgraded:
  openjdk-8-jdk openjdk-8-jre openjdk-8-jre-headless
3 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 81.2 MB of archives.
After this operation, 52.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]

In that case an 'sudo apt-get autoremove' is suggested and additional packages are also suggested. We have also an idea of the openjdk-8-source estimated size of 52,1 MB. Once installed I got a new directory below my '/usr/lib/jvm' directory. 'openjdk-8' exists and contains the needed 'src.zip' file thus fixing the reported broken link.

Enjoy

  • No labels