Dmytro Chyzhykov's Blog

Yet another programmer.

Installing Oracle Java 7 on Debian Linux

A quick reference for Debian Linux users who are going to install Oracle Java 7.

Getting Oracle Java 7

At first you should obtain your own copy of JDK/JRE from the Java SE Downloads page. Just Accept License Agreement and you’ll be able do download suitable gzipped tarball.

File system preparation

Then extract downloaded archive to an installation directory. In my case it is /usr/java

1
$ sudo tar xfvz jdk-7u5-linux-i586.tar.gz -C /usr/java

In order to be able to update Java installation create an easy-to-use structure of symbolic links

1
2
3
$ cd /usr/java
$ sudo ln -s $PWD/jdk1.7.0_05 latest
$ sudo ln -s $PWD/latest default

When you decide to change or update Java installation you just need to point one of the latest or default symbolic links to an appropriate installation.

The /usr/java/default path will be used in the rest of the reference.

Installing an alternative

The Debian alternatives system maintains software with the same or similar functionality of different version which are installed simultaneously but with one particular implementation designated as the default.

So we are going to use it to install yet another alternative.

1
$ sudo update-alternatives --install /usr/bin/java java /usr/java/default/bin/java 300

Where

  • /usr/bin/java is a generic name (or alternative link), which refers, via the alternatives system, to one of a number of files of similar function
  • java – alternative name of a symbolic link in the alternatives directory
  • /usr/java/default/bin/java is the alternative path which is a name of a specific file in the filesystem, which may be made accessible via a generic name using the alternatives system
  • 300 is a priority of the given alternative.

Updating alternatives

In order to check our Java installation and choose one run

1
$ sudo update-alternatives --config java

and you should see something like that:

1
2
3
4
5
6
7
8
9
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode
  1            /usr/java/default/bin/java                      300       manual mode
  2            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode

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

Select an appropriate one by typing its number (in my case it’s 1) and the fresh installed Oracle Java 7 will be used on your Debian machine.

Verifying the installation

When you execute

1
$ java -version

you should see

1
2
3
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) Server VM (build 23.1-b03, mixed mode)

Setting $JAVA_HOME environment variable

If you’ve installed JDK and you are planning to use your machine in Java development you should set $JAVA_HOME environment variable in the global system /etc/bash.bashrc bash configuration or in your user’s local ~/.bashrc one.

Just add the following lines at the end of the chosen bash configuration

1
2
3
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
 

And apply the changes by executing

1
2
$ source /etc/bash.bashrc
$ source ~/.bashrc

After that your should be able to reach Java Compiler and others from JDK.

Just verify it.

1
2
$ javac -version
javac 1.7.0_05