Thursday, 24 January 2013

Installing and configuring Oracle Java 7 - Ubuntu 12.10

Installing and configuring Oracle Java 7 
- Ubuntu 12.10

This guide explores the installation and configuration steps to get Oracle Java (NOT OPENJDK !!) up and running on your Ubuntu Server.

In this guide, I am using a Ubuntu 12.10 Desktop machine, however, the same steps will work on most other Ubuntu releases as well.

So... lets get started !!

To install Java in Ubuntu or Linux Mint, open a Terminal (Press Ctrl+Alt+T) and copy the following commands in the Terminal:

First, create a directory that will house the Java Folders:

# mkdir -p /usr/local java

The next step is to download the JDK and JRE Tar files from the net. You can achieve this is two ways:

  1. Download the tars from Oracle Java's site and manually place them in you Ubuntu machine
  2. Use wget to download the tars directly into your Ubuntu machine (This is shown below)

# wget -O jdk-64bit.tar.gz

NOTE: If you are using a 32 Bit Ubuntu Machine, then use a 32 Bit JDK ONLY. You can download the same at Oracle Java's Site ( or use the wget command as shown below:

FOR 32 Bit JDK: wget -O jdk-32bit.tar.gz

Do the same for the JRE Tar as well.

# wget -O jre-64bit.tar.gz

NOTE: If you are using a 32 Bit Ubuntu Machine, then use a 32 Bit JRE ONLY. You can download the same at Oracle Java's Site ( or use the wget command as shown below:

FOR 32 Bit JRE: wget -O jre-32bit.tar.gz

Once the two tars are downloaded, copy / move them to the new folder that we created during step 1.

# cp -r jre-7u12-ea-bin-b05-linux-4bit.tar.gz /usr/local/java 
# cp -r jdk-7u12-ea-bin-b05-linux-4bit.tar.gz /usr/local/java

Once moved, access the newly created folder and apply execute permissions to both the tar files as shown:

# cd /usr/local/java
# chmod a+x jre-7u12-ea-bin-b05-linux-4bit.tar.gz
# chmod a+x jdk-7u12-ea-bin-b05-linux-4bit.tar.gz

Once the correct permissions are granted, simply extract the contents from both the tars

# tar -xvzf jdk-7u12-ea-bin-b05-linux-4bit.tar.gz

# tar -xvzf jre-7u12-ea-bin-b05-linux-4bit.tar.gz

(OPTIONAL) Once both the tars are successfully extracted, you can delete the tar files if you do not wish to keep them. 

# rm  jdk-7u12-ea-bin-b05-linux-4bit.tar.gz
# rm  jre-7u12-ea-bin-b05-linux-4bit.tar.gz 

Now you need to enter these command (for both 32-bit and 64-bit JDK/ JRE): 

# nano /etc/profile


Add the following lines at the end of the file as shown:

export JAVA_HOME
export JRE_HOME
export PATH

Copy above lines and to paste in terminal (Press Ctrl+Shift+V) and to save file using nano (Press Ctrl+O) then (Press Ctrl+X) to exit from file. 

IMP NOTE: In this step, you have set the Java variables for root user ONLY. You need to do the exact same steps for other users in your Ubuntu system as well. Each local Ubuntu user has his own .profile file. You can locate it in the User's respective home directories.

Now enter following commands one by one in terminal:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_12/bin/java" 1

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_12/bin/javac" 1

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_12/bin/javaws" 1

sudo update-alternatives --set java /usr/local/java/jre1.7.0_12/bin/java

sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_12/bin/javac

sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_12/bin/javaws

. /etc/profile

Voila !! Thats it !! You now have Java successfully installed and configured on your Ubuntu system. You can verify this by typing the following command:

# Java -version 

You should see a similar output as shown.

Stay tuned for more such How-To guides coming your way soon !!

1 comment :

mary Brown said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

Post a Comment