How to Install Java JDK9 on Linux?
Last Updated :
06 Oct, 2021
As we all know Java is widely used in tech industries, with around 4 billion devices currently using java. This Java installation is going to be very easy and beginner-friendly. In this article, we are going to see a step-by-step guide on how you can install java on your Linux machine.
Step-By-Step Process For Installation
Step 1: Downloading JAVA archive binary file head to the link, download and save this archive file on your computer.

Downloading archive binaries
Step 2: Create an empty directory where you want to install JAVA and copy the downloaded file to that directory.

Created a new Folder (JAVA_GEEK)
Here we created a new folder with the name JAVA_GEEK ( you can name anything), and copy the archive file (jdk-9.0.4_linux-x64_bin.tar.gz) from downloads to the JAVA_GEEK folder.
We can copy and paste through the terminal or by simply drag a file from downloads to the JAVA_GEEK folder. Here is the command to do so through the terminal.
Syntax:
$ cp '/home/amninder/Desktop/JAVA_GEEK/jdk-9.0.4_linux-x64_bin.tar.gz' /home/amninder/Desktop
After Copying folder should look like this:

Successfully Copied
Step 3: Extract the archive file (jdk-9.0.4_linux-x64_bin.tar.gz) using the following command :
$ tar -xf jdk-9.0.4_linux-x64_bin.tar.gz

Extracting binary archive
This command with extract the binary file and after extracting the file structure should look like this:

After Extracting.
Step 4: Setting JAVA environment variables
Why Setting environment variables ?
We set some environment variables to make some things easier. Suppose we don’t set environment variables, in that case if we have to compile a program every time we have to specify the full path of the java bin.
For example: you’re compiling a Helloworld program then you have compiled it like this.
$ /home/amninder/Desktop/JAVA_GEEK/jdk-9/bin javac Helloworld.java
But after setting up variables same thing we can achieve by using javac program-name
For Example: Compiling a Helloworld program.
$ javac Helloworld.java
As we can see the difference now, and we know why we should set up variables.
Setting of Java Environment Variables
Firstly Open up the terminal by pressing Ctrl+Alt+T or you can search the terminal in applications. And then type :
nano /home/amninder/.bashrc
nano is a text editor mostly used in Linux to edit files. Here we are opening the bashrc file is the file where we will provide environment variables, function, and custom alias, this file loads automatically in the background when we open a new terminal every time.
It should look like this, then navigate to the bottom of the file and the type of the JAVA bin path like this:
export PATH="$PATH:/home/amninder/Desktop/JAVA_GEEK/jdk-9.0.4_linux-x64_bin/jdk-9.0.4/bin"

Setting JAVA Path
After writing the command, press Ctrl+X and type y, and exit the shell.

Step 5: Setting up default JVM :
Now to inform the system where java and its executable is installed we have to use the update-alternatives command as follows(if you have more than one JDK installed):
$ sudo update-alternatives –install /usr/bin/java java /home/amninder/Desktop/JAVA_GEEK/jdk-9.0.4_linux-x64_bin/jdk-9.0.4/bin/java 100
Update-alternatives is a special command that is in use to updates the links in “/etc/alternatives” to point to other programs.
Similarly, we can do the same for javac also:
$ sudo update-alternatives –install /usr/bin/javac javac /home/amninder/Desktop/JAVA_GEEK/jdk-9.0.4_linux-x64_bin/jdk-9.0.4/bin/javac 100
After creating links, now we can choose between different installation version of java by running the following command:
$ sudo update-alternatives --config java
After that, it will ask you to choose a default JAVA:

Selecting default java
You have to select the corresponding number as 0 shows for the first version,1 for second so on…
Step 6: Verifying Installation
Finally, the JAVA has been successfully installed on your Linux system, to verify the installation type the following command:
java -version

JAVA Installed successfully
How to Uninstall jdk9?
Remove the java link
$ sudo update-alternatives –remove java /home/amninder/Desktop/JAVA_GEEK/jdk-9.0.4_linux-x64_bin/jdk-9.0.4/bin/java

Removing java from alternative links
Remove the javac link
$ sudo update-alternatives –remove javac /home/amninder/Desktop/JAVA_GEEK/jdk-9.0.4_linux-x64_bin/jdk-9.0.4/bin/javac

Removing javac from alternative links
Remove the folder where you installed the java
$ sudo rm -rf /home/amninder/Desktop/JAVA_GEEK/jdk-9.0.4_linux-x64_bin

Removing Java folder
Similar Reads
How to Install Java on Arch Linux?
Java is one of the most popular programming languages. Today, many applications are using Java. Java consists of JRE (Java Runtime Environment) and JDK (Java Development Toolkit). JRE is the  Java Runtime Environment which is provided libraries to run and compile Java programs. JDK provides the comp
3 min read
How to Install Jekyll on Linux?
Jekyll is software used for creating websites. It can create websites more dynamically. Jekyll is useful nowadays. It can convert simply written text files into website documentation. It is simple to use. There is no database required for using Jekyll. It is very easy to use. Jekyll is platform-inde
2 min read
How to Install Keras on Linux?
Keras is an open-source software library that offers a Python interface for ANN (artificial neural networks). It acts as an interface for the TensorFlow library. It offers consistent & simple APIs, minimizes the number of user actions required for common use cases, and provides clear & actio
2 min read
How to Install JDK in Linux?
Java is a very popular general-purpose programming language, which is very close to flow Oop's theory and can run independently on any platform, but its run time environment is dependent on the platform the JVM (Java Virtual Machine) is also known as. Which first interprets Java file byte code and b
2 min read
How to Install Kotlin on Linux?
Kotlin is a programming language introduced by JetBrains in 2011, the official designer of the most intelligent Java IDE, named Intellij IDEA. This is a strongly statically typed general-purpose programming language that runs on JVM. In 2017, Kotlin is sponsored by Google, announced as one of the of
2 min read
How to Install Node.js on Linux
Installing Node.js on a Linux-based operating system can vary slightly depending on your distribution. This guide will walk you through various methods to install Node.js and npm (Node Package Manager) on Linux, whether using Ubuntu, Debian, or other distributions. PrerequisitesA Linux System: such
6 min read
How to Install PHP on Linux?
PHP is a popular server-side scripting language that is especially used in web development. If you're working on a Linux environment, whether it's a personal development setup or a production server, you will likely need PHP installed. In this article, we will see the step-by-step guide to install P
2 min read
How to Install Java on macOS?
The Java Development Kit (JDK) is an essential tool for developers working with Java. It provides the necessary tools and libraries to build, compile, and run Java applications, making it a cornerstone for efficient and effective Java development. Without the JDK, writing and testing Java programs w
7 min read
How to Install Java JDK11 on AWS EC2?
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
2 min read
How to Install Java Applet Viewer on Linux?
Applet viewer is a command-line program to run a java applet. It helps you to test an applet before you run it in the browser. The applet's code gets transferred to the system & then the Java Virtual Machine (JVM) of the browser & executes that code. In this article, we will look into the pr
2 min read