This post shows how to install Orcale JDK using apt-get or by downloading from the Oracle site on Ubuntu. It also shows how to install OpenJDK.
Installing Oracle JDK using apt-get
For installing Java in Ubuntu first you need to add Oracle’s PPA (Personal Package Archive) so that Ubuntu knows where to look for updates.
sudo add-apt-repository ppa:webupd8team/java
Here note that this repository is not maintained by Oracle. You can refer this URL– http://www.webupd8.org/p/ubuntu-ppas-by-webupd8.html. But the WebUpd8 Oracle Java PPA doesn’t include any Java binaries, just a script that automatically downloads and install Oracle Java 8.
Then you need to update your package repository. For that use the following command.
sudo apt-get update
After that install Oracle JDK. For that use the following code.
sudo apt-get install oracle-java8-installer
Installing Oracle JDK by downloading manually
If you want to manually download and install Oracle JDK then follow the given steps. You may opt for this way of installing Java in Ubuntu if you are behind a proxy/firewall that is creating problem with connecting to repository.
Go to – http://www.oracle.com/technetwork/java/javase/downloads/index.html and download the required version of Oracle JDK.
Create a directory /usr/java for your Java installation-
By default gzip file will be downloaded in Downloads directory so copy it from there to the directory /usr/java which you have created.
Then untar the installation.
Setting JAVA_HOME environment variable and Java path
In order to find where Java is installed applications refer to JAVA_HOME environment variable. So you need to set up the environment variable and also append the path to Java /bin directory to the PATH. For that you need to edit /etc/environment file.
sudo gedit /etc/environment
append path to bin in existing PATH- :/usr/java/jdk1.8.0_151/bin
Add JAVA_HOME environment variable at the end of the file.
Make sure to use installation path as per your Java installation.
After that reload the variables by running this command
You can verify that the environment variable is set correctly or not by running the following command-
Also check the Java installation by running the following command –
You should get the output for the version you have installed which should look something like this.
java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
If you want to install OpenJDK
sudo apt-get install openjdk-8-jdk
If you want to install just the Java Runtime Environment
sudo apt-get install openjdk-8-jre
- Installing Java in Windows
- How to dual-boot Ubuntu and Windows
- Package in Java
- Array in Java
- Equality And Relational Operators in Java
- Difference Between “==” Operator And equals() Method in Java
- Java Pass by Value or Pass by Reference
- Why main Method static in Java
That’s all for the topic Installing Java in Ubuntu. If something is missing or you have something to share about the topic please write a comment.
You may also like