Installing Java on Debian

1 minute read

If you need to install Oracle Java on Debian, you can follow the next steps once the binary file had been downloaded from Oracles’s download page:

Once it has been downloaded, proceed to extract it into the /opt directory:

# tar xvzf jdk-8u45-linux-x64.tar.gz

First let’s check the current java version:

# java -version

java version “1.7.0_79” OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

Here you can see it points to OpenJDK’s 1.7.0_79 version. Now let’s add a path to the version to use:

# update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_45/bin/java 1

Last line adds the /opt/jdk1.8.0_45/bin/java path to /usr/bin/java java  binary, in other words, it creates a symbolic link to use in case that options is chosen. Let’s set an alternative that points to the new path:

# update-alternatives --config java
  Selection Path Priority Status
* 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
 1 /opt/jdk1.8.0_45/bin/java 1 manual mode
 2 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
 3 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode

 Enter to keep the current selection[+], or type selection number:

After choosing the option 1, check the java version one more time:

# java -version

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Now the binary points to the Oracle’s version. You can check it with the symbolic links:

# ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 jun  9  2014 /usr/bin/java -> /etc/alternatives/java

# ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 25 jun 15 09:21 /etc/alternatives/java -> /opt/jdk1.8.0_45/bin/java

Leave a Comment