Install Java JDK on Ubuntu Linux

This post will list down the steps to install Oracle Java JDK in Ubuntu. I’ve Ubuntu 16.04 in my system but any other Debian based Linux operating systems should be compatible with these steps. Also my Ubuntu operating system architecture is 64-bit.

Steps

  1. Remove OpenJDK, if installed. By default OpenJDK is installed in Ubuntu.
  2. $ java -version
    openjdk version "1.8.0_91"
    OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
    OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
    
    $ sudo apt-get purge openjdk-\*
  3. Create java directory to keep Java JDK and JRE binaries.
  4. $ sudo mkdir -p /usr/local/java
  5. Download the latest version of Oracle Java JDK for Linux
  6. Move the Java binary into the /usr/local/java directory
  7. $ cd ~/Downloads/
    ~/Downloads$ sudo cp -r jdk-8u101-linux-x64.tar.gz /usr/local/java
    $ cd /usr/local/java/
    $ ls -lt
    total 177112
    -rw-rw-r-- 1 kuntal kuntal 181352138 Sep 13 15:58 jdk-8u101-linux-x64.tar.gz
    
  8. Extract there
  9. $ sudo tar xzvf jdk-8u101-linux-x64.tar.gz
    $ ls -a
    .  ..  jdk1.8.0_101  jdk-8u101-linux-x64.tar.gz
  10. Update system path file to add these system variables to the system path
  11. $ sudo vim /etc/profile
    JAVA_HOME=/usr/local/java/jdk1.8.0_101
    PATH=$PATH:$JAVA_HOME/bin
    export JAVA_HOME
    export PATH
    
  12. Inform Operating system about Java path
  13. $ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_101/bin/java" 1
    update-alternatives: using /usr/local/java/jdk1.8.0_101/bin/java to provide /usr/bin/java (java) in auto mode
    
    $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_101/bin/javac" 1
    update-alternatives: using /usr/local/java/jdk1.8.0_101/bin/javac to provide /usr/bin/javac (javac) in auto mode
    
    $ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_101/bin/javaws" 1
    update-alternatives: using /usr/local/java/jdk1.8.0_101/bin/javaws to provide /usr/bin/javaws (javaws) in auto mode
    
  14. Inform Operating system that Oracle Java JDK must be the default Java
  15. $ sudo update-alternatives --set java /usr/local/java/jdk1.8.0_101/bin/java
    
    $ sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_101/bin/javac
    
    $ sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_101/bin/javaws
    
  16. Reload system wide PATH /etc/profile
  17. $ source /etc/profile
  18. That’s all to get Java successfully installed in the system
  19. $ java -version
    java version "1.8.0_101"
    Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
    
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s