Java is known for it's cross-platform compatibility, and it's used by several developers to build applications and websites due to its speed, reliability and safety. Java runs on several devices today, including servers, smartphones, gaming consoles and more.
Java JDK and JRE are widely used in all kinds of software. Java developers require the Java Development Kit (JDK) for development, and the Java Runtime Environment (JRE) is required for running end user java applications. You can have several instances of Java installed on the same computer, be it the JDK and JRE.
After 3 years, a new version of Java has been released - it's Java 9. After several months of testing, it was finally rolled out in September 2017 and is available on all platforms with newer features and improvements.
We'll focus on installing JDK 9 via the source, which works for all Linux distros like Ubuntu, Manjaro, Arch Linux, Fedora. Then use apt-get for Debian-based systems like Ubuntu, Linux Mint and finally for RPM-based systems like RedHat.
Installing on Ubuntu 16.o4, Mint 18.2 or Debian 9
If you're running Ubuntu, Mint or Debian, you can install JDK 9 using the apt utility for Debian-based operating systems. Java JDK 9 for Debian-based distros is hosted on the webupd8 repository and we'll be installing it from there.
# add-apt-repository ppa:webupd8team/java # apt-get update # apt-get install oracle-java9-installer
The webupd8team repo officially supports Ubuntu 17.10, 17.04, 16.04, 14.04 and 12.04 but works for all Debian systems.
Installing from source
You can install Java 9 directly from the source. Follow the steps below to download and install Java 9.
$ wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" \ "http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz" # cp jdk-9_linux-x64_bin.tar.gz /opt # tar -xzf /opt/jdk-9_linux-x64_bin.tar.gz # rm /opt/jdk-9_linux-x64_bin.tar.gz
Installing on CentOS 7, Fedora 26, or RedHat 7.4
For RPM-based distributions of Linux like Fedora, CentOS, RedHat and Madriva run the following command from the terminal to download Java 9 and install it via RPM.
$ wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" \ "http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.rpm" # rpm -ivh jdk-9_linux-x64_bin.rpm
Configuring Java JDK 9
Verifying Your Java Installation
To verify whether your JDK 9 installation was successful, issue the following command:
$ java -version java version "9" Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
Setting Java 9 As Default Java Instance
Your environment may have different versions of Java and you'll need to set Java 9 as default Java, to do that run these commands:
# update-alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 1000 # update-alternatives --install /usr/bin/javac javac /opt/jdk-9/bin/javac 1000 # update-alternatives --install /usr/bin/javadoc javadoc /opt/jdk-9/bin/javadoc 1000 # update-alternatives --install /usr/bin/javap javap /opt/jdk-9/bin/javap 1000 # update-alternatives --config java
After the last command, enter the corresponding number of your Java 9 installation and press
Setting up Java Environment Variables
This is required to run some java applications. Set up the JAVA_HOME environment variable by adding the following lines at the end of /etc/environment file using your favorite text editor:
export JAVA_HOME=/opt/jdk-9 export PATH="$PATH:$JAVA_HOME/bin"
You can load your variables quickly by typing:
# source /etc/environment
Adding Java 9 plugin to Firefox
For additional Java 9 functionality in your browser, you can install the plugin to Firefox. The plugin file is included as part of your Java 9 installation. Before you install the plug in, make sure Firefox is closed and earlier versions of the plugin are removed along with their symbolic links.
For the 32-bit plugin:
$ cd Firefox/plugins $ ln -s lib/i386/libnpjp2.so .
For the 64-bit plugin:
$ cd Firefox/plugins $ ln -s /lib/amd64/libnpjp2.so .
After creating the symlinks, Start the Firefox browser and enter
about:plugins in the address bar to confirm that the Java plugin is loaded.
Uninstalling Java 9
Removing Java 9 from your Linux system is pretty easy. For Debian-based distros:
# apt purge oracle-java9-installer
For RPM based-systems:
# rpm -e jdk*
You can also uninstall Java 9 by removing the entire installation directory. Type
which java to find the present locations of java and remove them. Then type the following command:
# rm -rf /opt/jdk-9
In this guide, we tried to install Oracle Java 9 on different Linux distros and then configure it. What are your thoughts on the latest release of Java?