Install java (jdk) on Linux

Introduction

If you have downloaded java development kit (JDK) Linux binary tar.gz file from oracle.com (e.g jdk-7u21-linux-x64.tar.gz), you might probably be thinking how do I install it. On most Linux distributions, you might be able to install java or jdk using official or third party repository, but some people prefer doing it offline. In this tutorial, I will try to explain that.

Installation

Unzip the downloaded tar.gz binary file to some location in your computer. It would be wise to use a partition that you don’t delete during Linux upgrades. For this tutorial, I assume you have downloaded and unzipped the file in your home directory (/home/username). Lets say the unzipped directory is /home/username/jdk1.7.0. To install javac (compiler), java, and jar files run following commands

sudo update-alternatives --install /usr/bin/java java /home/username/jdk1.7.0/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /home/username/jdk1.7.0/bin/javac 1
sudo update-alternatives --install /usr/bin/jar jar /home/username/jdk1.7.0/bin/jar 1

Note: Change username to your own login username.

To know, if proper version of java is installed type java -version in a terminal.

Two instances

Suppose you had already installed openjdk before installing oracle jdk. If you want to choose one as default, use following command.

sudo update-alternatives --config java

Environment Variables (Optional)

Unless some program require, you don’t have to do this.  However, if some applications shows a message indicating a need for environment variables like JAVA_HOME or JDK_HOME you can add it to .bashrc (hidden) file in your home directory as following.

JAVA_HOME=/home/username/jdk1.7.0

Cheers !!

 

 

About these ads

Leave a comment

Filed under Uncategorized

Leave a Reply

Please log in using one of these methods to post your comment:

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