Before installing Oracle’s Java Development Kit (JDK), we will remove OpenJDK as Linux Mint comes with the OpenJDK version of Java libraries. Android development is an example of why OpenJDK should not be used.
Installing Oracle JDK on Debian / Linux Mint
1. Remove current OpenJDK or IcedTea installations.
sudo apt-get update
sudo apt-get remove openjdk* icedtea* default-jre default-jdk gcj-jre gcj-jdk icedtea-{6..7}-plugin icedtea-plugin
sudo apt-get autoremove
sudo apt-get autoclean
2. Download Oracle JDK here. Choose the correct version for your system architecture, x86 or x64. To determine if your system is 32 or 64 bit, run uname -m in a terminal.
3. Create a directory named java in /opt and move the downloaded JDK into /opt/java/ then extract the .tar.gz file there. At the time of writing, the JDK version was jdk-8u25-linux-x64.tar.gz
sudo mkdir /opt/java
sudo tar -zxvf jdk-8u25-linux-x64.tar.gz
4. Next we will set Oracle JDK as the default JVM. To set it as the default JVM in your machine, run the following:
sudo update-alternatives –install /usr/bin/java java /opt/java/jdk1.8.0_25/bin/java 100
sudo update-alternatives –install /usr/bin/javac javac /opt/java/jdk1.8.0_25/bin/javac 100
5. Verify that Java has been successfully installed.
java -version
javac – version
You should an output similar to the below:
zero@zenith:/opt/java$ java -version
java version “1.8.0_25”
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
zero@zenith:/opt/java$ javac -version
javac 1.8.0_25
Updating Java on Debian / Linux Mint
1. To update Java, simply download the latest version from Oracle’s website.
2. Extract the tarball under /opt/java then set it up as the default JVM with a higher priority number.
3. During installation we used 100 as the priority number, when updating use 110. Below is an example:
update-alternatives –install /usr/bin/java java /opt/java/jdk2.2.2_22/bin/java 110
update-alternatives –install /usr/bin/javac javac /opt/java/jdk2.2.2_22/bin/javac 110
4. (Optional) – Delete the old version of Java.
update-alternatives –remove java /opt/java/jdk.old.version/bin/java
update-alternatives –remove javac /opt/java/jdk.old.version/bin/javac
rm -rf /opt/java/jdk.old.version