How to install the JDK on Ubuntu Linux
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?
34 Answers 34
How to install Open JDK (Java developement kit) in Ubuntu (Linux)?
- Open Terminal from Application Dash or press Ctrl + Alt + T
- Update repository:
sudo add-apt-repository ppa:openjdk-r/ppa # only Ubuntu 17.4 and earlier sudo apt update
sudo apt install openjdk-8-jdk sudo apt install openjdk-8-source #this is optional, the jdk source code
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
I copied your «export PATH=» . command and screwed up my box. Please correct it to: «export PATH=$PATH:/usr/lib/jvm/java-6-openjdk/bin»
I’d replace export PATH=$PATH:/usr/lib/jvm/java-6-openjdk/bin with export PATH=$PATH:$JAVA_HOME/bin , which is more DRY
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.
This is what I used. If you want java6 : sudo apt-get install oracle-java6-installer . if you want java8 : sudo apt-get install oracle-java8-installer . If you have multiple java installed on your system, you can select with : sudo update-alternatives —config java
This is the easiest answer and working with all jdk versions, just replace java7 with java6, 8 or 9 and you will be able to install the version you want!
As of March 2019 the ppa was disabled and now 99% of the answer regarding this issue around the internet cannot be used anymore.
You can install Oracle’s JDK 1.7 fairly easily too; as an example this is how to install JDK 1.7.0_13;
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.
@Subash you need the downloaded file to be in th /usr/local directory before running the tar xzf command. To get that, cd to the path where your downloaded file is and run: sudo mv
You may also need to define aliases for JVM and Java Compiler and put them inside your ~/.profile file: alias java=’$JAVA_HOME/bin/java’ and alias javac=’$JAVA_HOME/bin/javac’
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 :
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
Note: WebUpd8 team’s PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn’t have any Java files. More information can be found on PPA’s page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
If you want to install the latest JDK 1.8, use the webupd8team PPA.
Add the repository in your system:
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update
You can now install Oracle Java 8 using the following command:
sudo apt-get install oracle-java8-installer
This ppa repository also provides a package to set environment variables automatically. Just type:
sudo apt-get install oracle-java8-set-default
OpenJDK is OK for the most cases, but Oracle JDK can be required for some bank client applications (my case) — I can’t use OpenJDK.
I’m surprised that I don’t see any answer with the default method (repository without external PPAs) in Ubuntu 12.10+ for Oracle’s JDK — I will try to describe it.
- Install JavaPackage: sudo apt-get install java-package
- Download Oracle JDK from Oracle downloads page
- Make a Debian package from the downloaded .tar.gz archive: make-jpkg jdk-YOUR_VERSION-linux-PLATFORM.tar.gz This command will produce a .deb package.
- Install the package in your favourite way (for example, sudo dpkg -i oracle-java8-jdk_8u40_amd64.deb )
It’s the officially supported way from Debian developers for installing Oracle JDK, and I suppose it’s very simple.
This is easily the best answer. Took a couple minutes and gave the official JDK, since some apps don’t like OpenJDK too much.
note: you can also install the documentation easily this way. this should be the most recommended way of installing java.
Note: WebUpd8 team’s PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn’t have any Java files. More information can be found on PPA’s page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
Installing Java 8 on Ubuntu
First you need to add webupd8team Java PPA repository in your system and install Oracle Java 8 using following set of commands.
$ sudo add-apt-repository ppa:webupd8team/java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer
Verify Installed Java Version
After successfully installing Oracle Java using the above steps, verify the installed version using the following command.
$ java -version java version "1.8.0_77" Java(TM) SE Runtime Environment (build 1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
###Configuring the Java environment
In Webupd8 ppa repository also providing a package to set environment variables, Install this package using following command.
$ sudo apt-get install oracle-java8-set-default
sudo apt-get install default-jdk
For Ubuntu 10.04 LTS, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" sudo apt-get update sudo apt-get install sun-java6-jre sun-java6-plugin sudo update-alternatives --config java
For Ubuntu 10.10, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner" sudo apt-get update sudo apt-get install sun-java6-jre sun-java6-plugin sudo update-alternatives --config java