To install Java in Linux, refer the following instructions:

1. Download the 32bit or 64bit compressed binary “.tar.gz” file from here.

2. Create a system directory like /usr/lib/jvm  to install JDK and copy the tar file to the directory.

sudo mkdir -p /usr/lib/jvm
sudo mv jdk-7u3-linux-x64.tar.gz /usr/lib/jvm/

 

3. Change the present working directory to the installation directory and extract the contents of the tar file using the following command.

cd /usr/lib/jvm
sudo tar -xzvf jdk-7u3-linux-x64.tar.gz

The name of the jdk folder will be like jdk1.7.0_03. 

 

4. Create the JAVA_HOME environment variable and add JDK bin path to the system PATH variable. Open /etc/environment file in an editor using sudo option.

sudo nano /etc/environment

Update the PATH variable and add the JAVA_HOME seting to the file

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/jdk1.7.0_03/bin"
JAVA_HOME="/usr/lib/jvm/jdk1.7.0_03"

To exit the editor, press ctrl+x and save your changes. Now, source the /etc/environment file to refresh the values of environment variables

source /etc/environment

 

5. Run following update commands to update the default java commands to use the installed JDK:

sudo update-alternatives --install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.7.0_03/bin/java” 1
sudo update-alternatives --install “/usr/bin/javac” “javac” “/usr/lib/jvm/jdk1.7.0_03/bin/javac” 1
sudo update-alternatives --install “/usr/bin/javaws” “javaws” “/usr/lib/jvm/jdk1.7.0_03/bin/javaws” 1

 

6. Correct the file ownership and the permissions of the executables:

sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_03

 

7. Check the version of your new JDK 7 installation:

 java -version

 

Continue reading more Linux blogs, click here.

Share this:

One thought on “Install Java in Linux

Leave a Reply to Nitin Mahesh Cancel reply

Your email address will not be published. Required fields are marked *