How to install oracle-java on ubuntu ?

Installing java on linux based system is not a headache, if you are following the right way.


  • There are x86 and x64 versions, you have to choose which is gonna fit on your machine. After choosing your architecture you need to download it. The package is available in two formats, 1. *.tar.gz 2. *.rpm. I personally prefer the hard way, so i choose tar.gz. Its not a big deal.
  • After downloading the file must be located in your downloads folder. Now we are going to deal with the package.
  • Open Terminal by CTRL + T or as you like. Type cd Downloads

  • tar xvzf “your complete file name with extension”
    eg: tar xvzf jdk-8u121-linux-x64.tar.gz

  • Now you  can see a new folder on your downloads, do not close your terminal unless we complete.

  • Now we are going to move this folder into a safe location where we need the root access. Usually i use the path /usr/lib/jvm/jdk8

  • We have to create a folder named jdk8 on the  /usr/lib/jvm/. So follow the command sudo mkdir /usr/lib/jvm/jdk8

  • Now move our folder by sudo mv “your folder name” /usr/lib/jvm/jdk8

  • Make sure that you have all the files inside /usr/lib/jvm/jdk8

  • Now we have all the necessary files inside our safe location. Now we have to tell our OS where we put our jdk. For that we have to edit your bashrc. To do that
    gedit ~/.bashrc

    Then goto the last line of your bashrc, then copy and paste these lines there

    export J2SDKDIR=/usr/lib/jvm/jdk8
    export J2REDIR=/usr/lib/jvm/jdk8/jre
    export PATH=$PATH:/usr/lib/jvm/jdk8/bin:/usr/lib/jvm/jdk8/db/bin:/usr/lib/jvm/jdk8/jre/bin
    export JAVA_HOME=/usr/lib/jvm/jdk8
    export DERBY_HOME=/usr/lib/jvm/jdk8/db

    Save it.

  • Now we have to load it, so perform the command source ~/.bashrc

  • Type javac and enter on terminal to see whether we have succeed or not

  • Perform a reboot, there you go…


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s