Friday, 4 November 2016

How to install JAVA in Linux OS?


In this article, I am going to share you how to install JAVA in Linux - ubuntu/CentOS in a step by step manner.

Things required before install JAVA in Linux OS:

1. Download the JAVA from website. 
       1.1 : Under Downloads  - Select Java for Developers  option under popular download menu.
       1.2 : Click on JDK download button.JDK Download Icon from

       1.3 : Navigates to JDK Download Page and select appropriate JDK file from the listed one.

        1. Before downloading the file, we need to accept the license and select the file to download
        2. File Format is to select tar.gz 
     Ex : jdk-8u111-linux-x64.tar.gz

2. Once the file download in your system, Open the terminal to unzip the file, from here onwards we use Unix commands to install JAVA.

   -  Unix commands are case-sensitive which means CD and cd are both different. 

3. First, navigate to file location path in terminal
      Ex: consider my JAVA file is in download location
          > cd download
4. To Unzip the tar file
         > tar -xvf  jdk-8u111-linux-x64.tar.gz
5.  Check whether java folder was there in /usr/lib/ folder, if java folder was not there then create the folder inside /usr/lib.
         5.1 : first navigate to /usr/lib path
                  > cd /usr/lib
         5.2 : Create a java folder using mkdir command
                 > mkdir java inside /usr/lib directory.
                -- If it throws permission error then run using sudo before mkdir command.
                > sudo mkdir java
         5.3 : Navigate to java folder and move the unzipped JDK file from Downloads to java folder.
                 java> sudo mv jdk-1.8.0_11/ /usr/lib/java
         5.4 : Navigate to /usr/lib/java/jdk1.8.0_11/bin/ directory and next run the following commands                    in the same path.
                 > sudo update-alternatives --install "/usr/bin/java" "java"                      "/usr/lib/java/JDK_VERSION/bin/java" 1
                 > sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/JDK_VERSION/bin/javac" 1
                 > sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/JDK_VERSION/bin/javaws" 1

        5.5 : Navigate to Home directory using the cd ~ command.

 6. Now we need to enter Java path in bashrc file
        > gedit ~/.bashrc
      6.1 : Enter the following path details
           # JAVA HOME path details
          export JAVA_HOME=/usr/lib/java/JDK_VERSION
          export PATH="$PATH:$JAVA_HOME/bin"   
      6.2 : Save and close the text editor file.
 /bashrc file contains all the environment path details and tells that JAVA path to run.

 7. Close the terminal and open the new terminal
       7.1 : For checking whether JAVA is installed correctly then type the following commands,
             > javac 
             >java -version  - Shows the version of JAVA installed in our machine.

NoteReplace JDK_VERSION to your installed version.

Please let your comments in the comments section and share to others if you feel really useful and worth.

Thanks and happy coding :)