Through this series we see how to install Java. In this article, we will look specifically at installing on Gentoo.

IcedTea

First we’ll set the USE flags.

For the default install, we’ll need to set these USE flags:

/etc/portage/package.use/java (Default)

1
2
x11-libs/cairo X
x11-libs/gdk-pixbuf X

If we want a headless Java install we’ll do this instead:

/etc/portage/package.use/java (Headless)

1
dev-java/icedtea-bin headless-awt -gtk

And if we want to go above and beyond the headless install, we can also drop alsa, cups, and webstart

/etc/portage/package.use/java (Minimal Headless)

1
dev-java/icedtea-bin headless-awt -gtk -alsa -cups -webstart

IcedTea 8

Once we’ve set the USE flags we can install Java 8.

Console - user@hostname ~ $

1
sudo emerge --ask --verbose dev-java/icedtea-bin:8

IcedTea 7

And/or we can install Java 7 like so:

Console - user@hostname ~ $

1
sudo emerge --ask --verbose dev-java/icedtea-bin:7

Oracle JDK

If we want a headless install, we’ll the USE flags like so:

/etc/portage/package.use/java (Headless)

1
dev-java/oracle-jdk-bin headless-awt

Make the license changes:

/etc/portage/package.license/java

1
dev-java/oracle-jdk-bin Oracle-BCLA-JavaSE

Try emerging the Oracle JDK:

Console - user@hostname ~ $

1
sudo emerge --ask --verbose dev-java/oracle-jdk-bin:1.8

There is a fetch restriction, which will give instructions along the lines of:

Output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Fetch instructions for dev-java/oracle-jdk-bin-1.8.0.92:
 *
 * Oracle requires you to download the needed files manually after
 * accepting their license through a javascript capable web browser.
 *
 * Download the following files:
 *   jdk-8u92-linux-x64.tar.gz
 * at 'http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html'
 * and move them to '/usr/portage/distfiles'
 *
 * If the above mentioned urls do not point to the correct version anymore,
 * please download the files from Oracle's java download archive:
 *
 *    http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html#jdk-8u92-oth-JPR
 *

Download the jdk-version-linux-x64.tar.gz file the fetch instructions required and put it in /usr/portage/distfiles. Then run the emerge command again.

Selecting the System JDK

List the available JDKs installed:

Console - user@hostname ~ $

1
java-config --list-available-vms

There is an * for the currently selected JDK:

Output

1
2
3
4
ec2-user@ip-172-30-0-196 ~ $ java-config --list-available-vms
The following VMs are available for generation-2:
1)      IcedTea JDK 7.2.6.6 [icedtea-bin-7]
*)      IcedTea JDK 3.0.1 [icedtea-bin-8]

We can see where the current JDK is installed:

Console - user@hostname ~ $

1
java-config --jdk-home

Output

1
/opt/icedtea-bin-3.0.1

We can switch to another JDK like so, in this case icedtea-bin-7:

Console - user@hostname ~ $

1
sudo java-config --set-system-vm icedtea-bin-7

Output

1
Now using icedtea-bin-7 as your generation-2 system JVM

Console - user@hostname ~ $

1
java-config --list-available-vms

Output

1
2
3
The following VMs are available for generation-2:
*)      IcedTea JDK 7.2.6.6 [icedtea-bin-7]
2)      IcedTea JDK 3.0.1 [icedtea-bin-8]

Console - user@hostname ~ $

1
java-config --jdk-home

Output

1
/opt/icedtea-bin-7.2.6.6

Setting JAVA_HOME

JAVA_HOME is automatically set, but you need to logout and back in again after installation for it to be set.

References

Parts of this series