Home > JAVA, Ubuntu > Installing Oracle JDK on Ubuntu

Installing Oracle JDK on Ubuntu

This tutorial will cover the installation of 64-bit Oracle Java 7 (7.0_75)

  1. Check to see if your Ubuntu system architecture is 32-bit or 64-bit, mine is 64 bit. Open up a terminal and run the following command below.
    bluething@ubuntu:~$ file /sbin/init
    /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]=7a4c688d009fc1f06ffc692f5f42ab09e68582b2, stripped
    bluething@ubuntu:~$
    
  2. Check if you have Java installed on your system. Mine doesn’t have any Java installed.
    bluething@ubuntu:~$ java -version
    The program 'java' can be found in the following packages:
    * default-jre
    * gcj-4.8-jre-headless
    * openjdk-7-jre-headless
    * gcj-4.6-jre-headless
    * openjdk-6-jre-headless
    Try: sudo apt-get install <selected package>
    bluething@ubuntu:~$
    

    If you have Java installed on your system, the command should return like this, for Ubuntu default Java is OpenJDK.

    java version "1.7.0_15"
    OpenJDK Runtime Environment (IcedTea6 1.10pre) (7b15~pre1-0lucid1)
    OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
    

    If you have Java installed on your system, remove the OpenJDK/JRE with the following command.

    sudo apt-get purge openjdk-\*
    
  3. Create a directory to hold your Oracle Java JDK/JRE binaries.
    bluething@ubuntu:~$ sudo mkdir -p /usr/local/java
    [sudo] password for bluething:
    bluething@ubuntu:~$ ls -l /usr/local
    total 36
    drwxr-xr-x 2 root root 4096 Apr 16 2014 bin
    drwxr-xr-x 2 root root 4096 Apr 16 2014 etc
    drwxr-xr-x 2 root root 4096 Apr 16 2014 games
    drwxr-xr-x 2 root root 4096 Apr 16 2014 include
    drwxr-xr-x 2 root root 4096 Mar 8 05:44 java
    drwxr-xr-x 4 root root 4096 Apr 16 2014 lib
    lrwxrwxrwx 1 root root 9 Mar 8 01:56 man -> share/man
    drwxr-xr-x 2 root root 4096 Apr 16 2014 sbin
    drwxr-xr-x 7 root root 4096 Apr 16 2014 share
    drwxr-xr-x 2 root root 4096 Apr 16 2014 src
    bluething@ubuntu:~$
    
  4. Download the Oracle Java JDK/JRE for Linux, you can find here. Make sure you select the correct compressed binaries for your system architecture 32-bit or 64-bit. I put on home directory.
  5. Unpack the compressed Java binaries to the directory /usr/local/java.
    bluething@ubuntu:~$ sudo tar xvzf jdk-7u75-linux-x64.tar.gz -C /usr/local/java
    bluething@ubuntu:~$ sudo tar xvzf jdk-8u40-linux-x64.tar.gz -C /usr/local/java
    bluething@ubuntu:~$ ls -l /usr/local/java
    total 8
    drwxr-xr-x 8 uucp 143 4096 Dec 18 17:04 jdk1.7.0_75
    drwxr-xr-x 8 uucp 143 4096 Feb 10 21:42 jdk1.8.0_40
    bluething@ubuntu:~$
    
  6. Edit the system PATH file /etc/profile and add the following system variables to your system path. I’m using gedit.
    JAVA_HOME=/usr/local/java/jdk1.7.0_75
    JRE_HOME=$JAVA_HOME/jre
    PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
    export JAVA_HOME
    export JRE_HOME
    export PATH
    
  7. Inform your Ubuntu Linux system where your Oracle Java JDK/JRE is located.
    bluething@ubuntu:~$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_75/bin/java" 1
    update-alternatives: using /usr/local/java/jdk1.7.0_75/bin/java to provide /usr/bin/java (java) in auto mode
    bluething@ubuntu:~$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_75/bin/javac" 1
    update-alternatives: using /usr/local/java/jdk1.7.0_75/bin/javac to provide /usr/bin/javac (javac) in auto mode
    bluething@ubuntu:~$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_75/bin/javaws" 1
    update-alternatives: using /usr/local/java/jdk1.7.0_75/bin/javaws to provide /usr/bin/javaws (javaws) in auto mode
    bluething@ubuntu:~$
    
  8. Inform your Ubuntu Linux system that Oracle Java JDK/JRE must be the default Java.
    bluething@ubuntu:~$ sudo update-alternatives --set java /usr/local/java/jdk1.7.0_75/bin/java
    bluething@ubuntu:~$ sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_75/bin/javac
    bluething@ubuntu:~$ sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_75/bin/javaws
    bluething@ubuntu:~$
    
  9. Reload your system wide PATH /etc/profile.
    bluething@ubuntu:~$ . /etc/profile
    bluething@ubuntu:~$
    

    Reboot Ubuntu

  10. Test to see if Oracle Java was installed correctly on your system.
    bluething@ubuntu:~$ java -version
    java version "1.7.0_75"
    Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)
    bluething@ubuntu:~$
    

 

Categories: JAVA, Ubuntu

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

%d bloggers like this: