the debian way

created onJanuary 20, 2022

configuring java the Debian way

download and installation

Download the JSDK tarball unpack it, i.e. into :

Install the jdk with :

# update-alternatives --install /usr/bin/java java /opt/local/jdk-1.8.0_51/bin/java 100 # update-alternatives --install /usr/bin/javac javac /opt/local/jdk-1.8.0_51/bin/javac 100

set the JDK as the default JDK

The priority given for java and javac (given at the end of bothh command lines above) may not set it as the default version.

# update-alternatives --display java java - auto mode link currently points to /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java /opt/local/jdk-1.8.0_51/bin/java - priority 100 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071 slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz Current 'best' version is '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'.

Set the installed version as the default:

# update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode 1 /opt/local/jdk-1.8.0_51/bin/java 100 manual mode 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode Press enter to keep the current choice[*], or type selection number: 1 update-alternatives: using /opt/local/jdk-1.8.0_51/bin/java to provide /usr/bin/java (java) in manual mode

Test the installed version

# ls -l /etc/alternatives/java lrwxrwxrwx 1 root root 32 Aug 10 14:29 /etc/alternatives/java -> /opt/local/jdk-1.8.0_51/bin/java
# update-alternatives --display java java - manual mode link currently points to /opt/local/jdk-1.8.0_51/bin/java /opt/local/jdk-1.8.0_51/bin/java - priority 100 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071 slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz Current 'best' version is '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'.
# java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

set the environment variables for Java

Add the follwing line to

JAVA_HOME="/opt/local/jdk-1.8.0_51"

after that, run

source /etc/environment

and verify that the environment var has been issued:

# echo $JAVA_HOME /opt/local/jdk-1.8.0_51

list available Java versions

# update-alternatives --list java /opt/local/jdk-1.8.0_51/bin/java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java