How to Install Java Development Kit in Linux

Posted on

A Foreword for Installing Java Development Kit (JDK) in Linux Operating System

This article is written to show how to install Java Development Kit (JDK) in Linux. The Java Development Kit (JDK) installation process steps in this article is compatible with any distribution types of Linux operating system. In this article, the installation process steps is using an Ubuntu-based operating system .

Steps for Installing Java Development Kit (JDK) in Linux Operating System

Without further explanation, the steps for installing Java Development Kit (JDK) are :

1. Download Java Development Kit (JDK).

This is the first step to begin the Java Development Kit (JDK) installation process. The Java Development Kit (JDK) installation in the context of this article is a binary file. The binary file is available in the official Java Download page. Actually, at the time this article is written, there is a specific page in this link to download Java Development Kit (JDK) 8 file installer. Fortunately, following available links in that page, there are also another page where all the other version of file installer is available for downloading as an alternative version. Download the proper file installer based on the requirement of the version.

Furthermore, try to visit the link containing all of the possible version of Java Development Kit (JDK). Normally, if those links are broken, just use another method to find the correct page. An alternative method is by typing the keyword ‘download java development kit’ in the google search engine to search the page. The page will normally visible in the first page of the search result.

2. Move the Java Development Kit (JDK) file installer into a specific location to process it further.

After completing the download process, if there is a specific location to extract the Java Development Kit (JDK) file installer, move it to a different place or a location just in case. Move it by typing the following command :

mv jdk-file-installer.tar.gz path/

Based on the above pattern, move the Java Development Kit (JDK) file installer into the specific location or path. It is a location or path for further extracting process :

user@hostname:/home/user/Downloads# mv jdk-8u181-linux-x64.tar.gz installer/temp/

3. Extract the Java Development Kit (JDK).

In the context of this article, the Java Development Kit (JDK) file installer is in compression format. It is a ‘tar.gz’ file format. First of all , to install the Java Development Kit (JDK), extract the file installer. Type the following command to extract the file :

tar -zxvf jdk-file-installer.tar.gz

In this article for an example, using the above pattern, below is the installation command :

user@hostname:/home/user/Downloads/installer/temp# tar -zxvf jdk-8u181-linux-x64.tar.gz
...
jdk1.8.0_181/jre/lib/psfont.properties.ja
jdk1.8.0_181/jre/lib/fontconfig.Turbo.properties.src
jdk1.8.0_181/jre/lib/jce.jar
jdk1.8.0_181/jre/lib/flavormap.properties
jdk1.8.0_181/jre/lib/jfxswt.jar
jdk1.8.0_181/jre/lib/fontconfig.SuSE.10.properties.src
jdk1.8.0_181/jre/lib/fontconfig.SuSE.11.bfc
jdk1.8.0_181/jre/COPYRIGHT
jdk1.8.0_181/jre/THIRDPARTYLICENSEREADME-JAVAFX.txt
jdk1.8.0_181/jre/Welcome.html
jdk1.8.0_181/jre/README
jdk1.8.0_181/README.html
user@hostname:/home/user/Downloads/installer/temp#

4. After moving and extracting the Java Development Kit (JDK), move it again to a specific path or location.

For further consideration, in order to isolate or to group all of binary files program, move it to specific a path or location. It is not a strict regulation to follow. But it is actually a certain way for managing the operating system in a good manner. In this context of article, the location for all of those kind of files is in ‘/opt’. The command for moving those Java Development Kit (JDK) file installer is :

mv jdk-folder-file-installer location

So, according to the command patter above, in the context of this article, the following is the actual command :

root@hostname:/home/user/Downloads/installer/temp#  mv jdk1.8.0_181/ /opt/
root@hostname:/home/user/Downloads/installer/temp#

3. Install the symbolic link.

Consequently, continue to do this step if the previous step is finished. This step is a step for installing the symbolic link where it represents the location or the path of the ‘java’ program. From the previous step, the path is in ‘/opt/jdk1.8.0_181’. In order to be able to install the symbolic link, ‘update-alternatives’ tool is quite useful to accomplish the task. There is an article in this site containing that kind of information. The title is ‘How to Install update-alternatives tool for maintaining symbolic link of a command’. It is about how to install symbolic link using ‘update-alternatives’ tool. It is available in this link. So, using the reference available from that article, execute the command to install a new symbolic link. Below is the command pattern to install the symbolic link representing the ‘java’ program :

update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_181/bin/java 2

Using the above command pattern, the execution of the command in the command line is :

root@hostname:/home/user/Downloads/installer/temp# update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_181/bin/java 2
root@hostname:/home/user/Downloads/installer/temp#

4. Check the symbolic link.

After completely finish the third step, check the symbolic link. This step is very useful to check if the previous step is properly done. The command for checking the list of the available symbolic link is shown as follows :

root@hostname:/home/user/Downloads/installer/temp# update-alternatives --display java
java - manual mode
  link best version is /usr/lib/jvm/java-11-openjdk-amd64/bin/java
  link currently points to /opt/jdk1.8.0_181/bin/java
  link java is /usr/bin/java
/opt/jdk1.8.0_181/bin/java - priority 1
/usr/lib/jvm/java-11-openjdk-amd64/bin/java - priority 2
root@hostname:/home/user/Downloads/installer/temp#

Also, search for further information or reference about how to display or to list symbolic link available for that program, . Fortunately, the information on how to display list of symbolic link for a specific program is available in this site. It is in an article about ‘update-alternatives’ tool. That article titled ‘How to List Available Specific Command using update-alternatives’. It is available in this link.

5. Test the command.

Finally, if the steps from 1 until 4 is finished, the last step is just a step for testing the command. Therefore, to test the command, type the program name in the command line. In the context of this article, the program name is ‘java’. This is the output for executing the command ‘java’ in the command line :

root@hostname:/home/user/Downloads/installer/temp# java 
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32      use a 32-bit data model if available
    -d64      use a 64-bit data model if available
    -server   to select the "server" VM
                  The default VM is server,
                  because you are running on a server-class machine.
    -cp 
    -classpath 
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D=
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:...|:]
    -enableassertions[:...|:]
                  enable assertions with specified granularity
    -da[:...|:]
    -disableassertions[:...|:]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:[=]
                  load native agent library , e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:[=]
                  load native agent library by full pathname
    -javaagent:[=]
                  load Java programming language agent, see java.lang.instrument
    -splash:
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
root@hostname:/home/user/Downloads/installer/temp# 

Finally, there is an efficient way to check the symbolic link. It is specifically check the detail version of the program. Apparently, it is a way to prove that the correct symbolic link representing the correct ‘java’ program. Moreover, it is available as an additional parameter comes with the command or the ‘java’ program. Hence, just type the following command in the command line :

root@hostname:/home/user/Downloads/installer/temp# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
root@hostname:/home/user/Downloads/installer/temp# 

So, using the additional parameter -version, the user is aware of the version of the java program. In summary, using the command above, the output of the version and the version of the java program in the location defines in the symbolic link is a match.

 

One thought on “How to Install Java Development Kit in Linux

Leave a Reply