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


2.1 Oracle JDK 6

You can download and install the JDK6 package from

You need to be registered in 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 trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver --recv-keys EEA14886
apt-get update
apt-get install oracle-java8-installer</code>


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:


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


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:

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>