How to install Java in Ubuntu / Linux ?

To install JAVA in ubuntu follow this steps.

1. Download JDK

First of all we required to download jdk for linux platform from Oracle’s website.
Downloaded file name would be like jdk-7u40-linux-i586.tar.gz

2. Extract Compressed file

Assume your file is in download folder, open your terminal type this command to extract tar.gz file.
tar -xvf ~/Downloads/jdk-7u40-linux-i586.tar.gz

3. Install JDK

Create a folder for your java installation by running this command

sudo mkdir -p /usr/lib/java/jdk
Now copy the extracted file content to this folder
sudo mv jdk1.7.0_40/* /usr/lib/java/jdk
To aware your system that you have installed java, run following command one by one.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/jdk/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/jdk/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/jdk/bin/javaws" 1

4. Set Environment Variable

After installation is complete, set  environment variables as follows

Edit the system Path file /etc/profile

sudo gedit /etc/profile
Add following lines in the end.
export JAVA_HOME
export JRE_HOME
export PATH
And yeah you are done.
Restart Terminal ,still its not working logout/login in system.

4 thoughts on “How to install Java in Ubuntu / Linux ?

  • June 8, 2015 at 6:33 pm

    It’s very useful for programming in java on Linux.

    If you have any knowledge about Hadoop and Mapreduce technology than please share it.

    • June 9, 2015 at 1:36 pm

      Thanks, I will share my knowledge about Hadoop/MapReduce examples as soon as possible. Keep in touch.

  • June 8, 2015 at 7:11 pm

    I am collage student,
    I am little-bit confuse about this topic,

    Shall I use localhost for run java program ??

    • June 8, 2015 at 7:36 pm

      No, this is just basic java setup. You can install tomcat and make your web application running on localhost.


Leave a Reply

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