Install Java on Debian

This entry is part 5 of 11 in the series Setup a Debian development environment (Web, Java, PHP)

1. Install OpenJDK

1.1 OpenJDK 6

apt-get install openjdk-6-jdk

1.2 OpenJDK 7

apt-get install openjdk-7-jdk

2. Install Oracle JDK

java

2.1 Oracle JDK 6

You can download and install the JDK6 package from http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html

You need to be registered in Oracle.com to proceed.

According to Debian documentation, Java packages are also available in non-free repositories.

2.2 Oracle JDK 7

First install the java-package (you may have to enable non-free and contrib repositories in /etc/apt/sources.list).

apt-get install java-package

Then, download the JDK7 package from Oracle Web site (browse the Web site and choose the appropriated version, e.g. jdk-7u21-linux-x64.tar.gz).

Then run with as normal user:

make-jpkg jdk-7u21-linux-x64.tar.gz

And finally, as root:

dpkg -i oracle-j2sdk1.7_1.7.0+update21_amd64.deb

2.3 Oracle JDK 8

<code>echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install oracle-java8-installer</code>

Source: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html

3. Default JAVA version & JAVA_HOME

To choose the java version to use by default, run:

update-alternatives --config java

To set JAVA_HOME, choose:

JRE:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

JDK:

export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")

3 replies on “Install Java on Debian”

  1. Arno says:

    Just some hints:

    - The wget command contains the version of the JRE. It will be better to choose the available version from Oracle.

    - There seems to be a typo after make-jpkg : the download is the JRE, the package command is the JDK

    - sources.list needs ‘contrib’ or ‘non-free’ or both for the java-package

    Thank you anyway, you have shown up the way!

  2. I found that Oracle was serving misnamed and broken “tarballs” off their download site which confused ‘make-jpkg’ … here’s my analysis and solution: http://gmorehou.wordpress.com/2013/08/05/de-failing-the-make-jpkg-oracle-java-7-jre-on-debian-wheezy-aug-2013/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>