How to Install Java – Ubuntu

Home / Installation / How to Install Java – Ubuntu

Here we are going to discuss about installing Oracle Java in Ubuntu 14.04. Before moving forward, first check if Java is already installed or not.

$ java -version

If output of this command says “java command not found”, then you are good to go. If it says “java version x.x.x_xx”, then you already have Java installed. Further to this, if output contains “OpenJdk” in it, then you have “OpenJdk Java” installed in your machine.

NOTE: For Android application development, “Oracle Java” is preferred.

To uninstall “OpenJdk”, run

$ sudo apt-get purge openjdk-\*

This will uninstall all the packages and dependencies installed with it. It would also uninstall the packages, which are completely dependent on Java. So, read the content before removing all dependencies.

Now, coming to installation of Oracle Java. There are two ways for doing this.

1. Download Java package from Oracle’s site, and install it.
2. Add “Webupd8 ppa” and install Oracle Java.

If you want to stick with only one version of Java, and want to update on your own terms. Then, choose option 1. On the other hand, if you like to stay updated and make more of updates, then choose option 2.

1. Download Java package from Oracle’s site, and install it.

Prior downloading a Java package, confirm your system architechure. That is, check if it is 32-bit (x86) or 64-bit (x64). To do that run following command

$ file /sbin/init

Output of this command would be like

/sbin/init: ELF 64-bit LSB  shared object, x86-64, version 1 (SYSV), dynamically
linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=7a4c688d009fc1f06ffc69
2f5f42ab09e68582b2, stripped
/sbin/init: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically
linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x5f722891935c0f35fd8f
318d4606b334a9b1d423, stripped

It is clearly visible that first one is 64-bit and second one is 32-bit. So, depending on output you get, proceed to download required Oracle Java package.

Click here to navigate to Oracle’s Java download page. Accept the license agreement and download a package. After download is completed, run following command in sequence to install Java.

$ sudo cp ~/Downloads/jdk-7u79-linux-x64.tar.gz /opt/
$ sudo tar xvzf /opt/jdk-7u79-linux-x64.tar.gz
$ sudo vim /etc/profile

Copy and paste following in the end of file

# Java installation
export JAVA_HOME
export JRE_HOME
export PATH

Exit vim (press Esc, then type :wq)

Reload settings in profile by running following command

$ source /etc/profile

Register java and other tools in /usr/bin to use it from anywhere in terminal.

$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk1.7.0_79/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/jdk1.7.0_79/bin/javac" 1

Now check Java installation

$ java -version

Output should be like

java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

2. Add “Webupd8 ppa” and install Oracle Java.

Run following commands in sequence to add “Webupd8 ppa” and install Java

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java7-installer

While installing, it will ask you to accept license agreement. To do that, use arrow keys or tab key to select <yes>, and press <enter> or <return> key.

Run following command to check the installation.

$ java -version

If for some reason(s), you don’t see any output as expected, run following command to update the alternatives.

$ sudo update-java-alternatives -s java-7-oracle

One Pingback/Trackback

  • Nippu Kumar

    Sir ji ,
    Plz also mention the step of installation of UBUNTU with windows.

    • Mr. Nippu, thanks for your post. We will try to post the process of Ubuntu installation along with Windows soon. Please subscribe or visit regularly to our website to keep posted about recent posts.

      PCSalt – Admin

  • Pingback: Create Andriod Application Project in Android Studio | PCSalt()

  • zadytem9

    Stay with this guys, you’re heiplng a lot of people.