How to install Oracle JDK 7 on ubuntu 12.04

To install Oracle JDK 7 on ubuntu 12.04

This tutorial will cover the installation of 32-bit and 64-bit Oracle Java 7 (currently version number 1.7.0_25) JDK/JRE on 32-bit and 64-bit Ubuntu operating systems. These instructions will also work on Debian and Linux Mint.

Check if you have Java installed on your system. To do this, you will have to run the Java version command from terminal.

#java -version

If you have OpenJDK installed on your system it may look like this:

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)

Completely remove the OpenJDK/JRE from your system and create a directory to hold your Oracle Java JDK/JRE binaries. This will prevent system conflicts and confusion between different vendor versions of Java. For example, if you have the OpenJDK/JRE installed on your system, you can remove it by typing the following at the command line:

#sudo apt-get purge openjdk-\*

This command will completely remove OpenJDK/JRE from your system

Download the Oracle Java JDK/JRE for Linux. Make sure you select the correct compressed binaries for your system architecture 32-bit or 64-bit (which end in tar.gz).

For example, if you are on Ubuntu Linux 32-bit operating system download 32-bit Oracle Java binaries.

For example, if you are on Ubuntu Linux 64-bit operating system download 64-bit Oracle Java binaries.

Important Information: 64-bit Oracle Java binaries do not work on 32-bit Ubuntu Linux operating systems, you will receive multiple system error messages, if you attempt to install 64-bit Oracle Java on 32-bit Ubuntu Linux.

Go to Oracle JDK7 download page. And download the latest linux jdk in .tar.gz format.

Copy your JDK .tar.gz file to your Desktop.

Open Terminal.To open terminal click the Dash home from unity launcher.And type terminal in the search field.And click Terminal.

Type the below code in terminal and hit enter to extract in Home folder.

#tar -zxvf ~/Desktop/jdk-7u25-linux-x64.tar.gz

Next Type below command in terminal to create a new folder.

#sudo mkdir -p /usr/lib/jvm/jdk1.7.0_7u25

Type your ubuntu password if needed and press enter.

Now type below command to move files.

#sudo mv jdk1.7.0_25/* /usr/lib/jvm/jdk1.7.0_7u25/

Inform your Ubuntu Linux system where your Oracle Java JDK/JRE is located. This will tell the system that the new Oracle Java version is available for use.

#sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_7u25/bin/java" 1

this command notifies the system that Oracle Java JRE is available for use

#sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_7u25/bin/javac" 1

this command notifies the system that Oracle Java JDK is available for use

#sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_7u25/bin/javaws" 1

this command notifies the system that Oracle Java Web start is available for use

Inform your Ubuntu Linux system that Oracle Java JDK/JRE must be the default Java.

#sudo update-alternatives --set java /usr/lib/jvm/jdk1.7.0_7u25/bin/java

this command will set the java runtime environment for the system

#sudo update-alternatives --set javac /usr/lib/jvm/jdk1.7.0_7u25/bin/javac

this command will set the javac compiler for the system

#sudo update-alternatives --set javaws /usr/lib/jvm/jdk1.7.0_7u25/bin/javaws

this command will set Java Web start for the system

Test to see if Oracle Java was installed correctly on your system. Run the following commands and note the version of Java:

A successful installation of 64-bit Oracle Java will display:

#java -version

This command displays the version of java running on your system

java version “1.7.0_25″
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

#javac -version

This command lets you know that you are now able to compile Java programs from the terminal.

You should receive a message which displays:

#javac 1.7.0_25

Congratulations, you just installed Oracle Java on your Linux system. Now reboot your Ubuntu Linux system. Afterwards, your system will be fully configured for running and developing Java programs.

How to set JAVA_HOME variable and the PATH variable to your Java installation.


#vim ~/.bashrc

export JAVA_HOME="/usr/lib/jvm/jdk1.7.0_7u25"
export PATH="$PATH:$JAVA_HOME/bin"

NOTE: If /usr/lib/jvm/java does not match the actual JAVA_HOME path in your environment, then set the actual JAVA_HOME, where you have installed Java in your machine.

Now run,
#source ~/.bashrc

Then, try running the following commands and check whether your getting the appropriate responses:

#echo $JAVA_HOME
/usr/lib/jvm/jdk1.7.0_7u25

#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/jdk1.7.0_7u25/bin

Optional: How to enable Oracle Java in your Web Browsers

To enable your Java plug-in in your web browsers you must make a symbolic link from the web browsers plug-in directory to the location of the Java plug-in included in your distribution of Oracle Java.

Google Chrome

Oracle Java instructions:

#sudo mkdir -p /opt/google/chrome/plugins

this will create a directory called /opt/google/chrome/plugins

#cd /opt/google/chrome/plugins

this will change you into the google chrome plugins directory,make sure you are in this directory before you make the symbolic link

for 64bit run following command,

#sudo ln -s /usr/lib/jvm/jdk1.7.0_7u25/jre/lib/amd64/libnpjp2.so

for 32bit run following command,

#sudo ln -s /usr/lib/jvm/jdk1.7.0_7u25/jre/lib/i386/libnpjp2.so

this will create a symbolic link from the Java JRE( Java Runtime Environment ) plugin libnpjp2.so to your Google Chrome web browser

Restart your web browser and go to Java Tester to test if Java is functioning in your web browser.

Mozilla Firefox

#cd /usr/lib/mozilla/plugins

this will change you into the directory /usr/lib/mozilla/plugins, create this directory if you do not have it

#sudo mkdir -p /usr/lib/mozilla/plugins

this will create the directory /usr/lib/mozilla/plugins, make sure you are in this directory before you make the symbolic link

for 64bit run following command,

#sudo ln -s /usr/lib/jvm/jdk1.7.0_7u25/jre/lib/amd64/libnpjp2.so

for 32bit run following command,

#sudo ln -s /usr/lib/jvm/jdk1.7.0_7u25/jre/lib/i386/libnpjp2.so

or

#cd /usr/lib/firefox-addons/plugins

#ln -s /usr/lib/jvm/jdk1.7.0_7u25/jre/lib/amd64/libnpjp2.so

How to set default Java version?

#sudo update-alternatives --config java

will return following output,

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/jdk1.7.0_7u25/bin/java 1 manual mode

Press enter to keep the current choice[*], or type selection number: 2

same procedure for javac compiler and javaws.

This entry was posted in Java, Web development and tagged , , . Bookmark the permalink.

Leave a Reply