Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install the JDK on Ubuntu Linux

Tags:

java

ubuntu

Note: This is an old question and the answers reflect the world as it was then. Modern Ubuntu distributions have OpenJDK available which can be installed with

sudo apt install default-jdk

I am trying to install the Java Development Kit (JDK) on Ubuntu Linux distribution, but I am unable to install it.

What are the steps to install it on Ubuntu?

like image 535
user2057084 Avatar asked Feb 09 '13 12:02

user2057084


4 Answers

Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,

How to install Open JDK (Java developement kit) in Ubuntu (Linux)?

  1. Open Terminal from Application Dash or press Ctrl+Alt+T

  2. Update repository:

    sudo add-apt-repository ppa:openjdk-r/ppa  # only Ubuntu 17.4 and earlier
    sudo apt update
    
  3. Optional: To search available distributions of openjdk, use the following command:

    apt search openjdk
    
  4. Install the appropriate version with the following command:

    sudo apt install openjdk-8-jdk
    sudo apt install openjdk-8-source #this is optional, the jdk source code
    
  5. For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path...

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
    

    (Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.)

  6. For PATH (Environment Variable) type command as shown below, in Terminal:

    export PATH=$PATH:$JAVA_HOME/bin

  7. To check your installation:

    java -version

like image 70
Dhaval Shah Avatar answered Oct 19 '22 03:10

Dhaval Shah


The following used to work before the Oracle Java license changes in early 2019.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

The PPA is discontinued, until the author finds a workaround for the license issues.

like image 36
Julio Marins Avatar answered Oct 19 '22 03:10

Julio Marins


You can install Oracle's JDK 1.7 fairly easily too; as an example this is how to install JDK 1.7.0_13;

  • Download the JDK from Oracle's site. The download to the newest version is always linked from http://java.oracle.com.

As root, do;

cd /usr/local
tar xzf <the file you just downloaded>

As your normal user, add or change these two lines in your ~/.profile to point to the installation;

export JAVA_HOME=/usr/local/jdk1.7.0_13
export PATH=$PATH:$JAVA_HOME/bin

If it's an update, you may also want to remove the old java installation directory in /usr/local.

Log out and in again (or do . ~/.profile), and everything should just work.

The downside with Oracle's JDK is that it won't update with the rest of your system like OpenJDK will, so I'd mostly consider it if you're running programs that require it.

like image 146
Joachim Isaksson Avatar answered Oct 19 '22 03:10

Joachim Isaksson


In case you have already downloaded the ZIP file follow these steps.

Run the following command to unzip your file.

tar -xvf ~/Downloads/jdk-7u3-linux-i586.tar.gz
sudo mkdir -p /usr/lib/jvm/jdk1.7.0
sudo mv jdk1.7.0_03/* /usr/lib/jvm/jdk1.7.0/
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1

After installation is complete, set environment variables as follows.

Edit the system path in file /etc/profile:

sudo gedit /etc/profile

Add the following lines at the end.

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

Source: http://javaandme.com/

like image 79
Pratap Singh Avatar answered Oct 19 '22 04:10

Pratap Singh