You are here
Home > How To > How to install-uninstall Oracle Java 8 on Ubuntu 18.04

How to install-uninstall Oracle Java 8 on Ubuntu 18.04

install-Oracle-Java-8

Here we are going to learn How to install Oracle Java 8 on Ubuntu 18.04. Java and the JVM (Java’s virtual machine) are widely used and required for many kinds of software. This article will guide you through the process of installing and managing different versions of Java using apt-get

Steps to install the Oracle JDK on Ubuntu 18.04:

  • First, add Oracle’s PPA
  • If you want to install the Oracle JDK, which is the official version distributed by Oracle, you will need to add Oracle’s PPA repositories first, To do so follow the command below:

    $sudo add-apt-repository ppa:webupd8team/java

    Java PPA

  • Update your package repository
  • After installing the PPA repository for the Oracle Java 8, you need to update the packages and repositories using the following command.

    $sudo apt-get update

    Update Package

  • Install Java
  • Then, depending on the version you want to install, execute one of the following commands:

    • Oracle JDK 8
    • This is the latest stable version of Java at time of writing, and the recommended version to install. You can do so using the following command:

      $sudo apt-get install oracle-java8-installer

      install java8

    • Oracle JDK 9
    • This is a developer preview and the general release is scheduled for March 2017. It’s not recommended that you use this version because there may still be security issues and bugs. There is more information about Java 9 on the official JDK 9 website.To install JDK 9, use the following command:

      $ sudo apt-get install oracle-java9-installer
  • Managing Java
  • There can be multiple Java installations on one server. You can configure which version is the default for use in the command line by using update-alternatives, which manages which symbolic links are used for different commands.

    $ sudo update-alternatives –config java

    You can also set the Java 8 as a default Oracle Java Version using below command

    $sudo apt-get install oracle-java8-set-default
  • Confirm the java version:
  • $ java -version

    default_java

    You can also open and check the java application graphically using Search your Ubuntu Applications box. Refer to the snapshot below.

    confirm_java_version

    Setting the JAVA_HOME Environment Variable

    Many programs, such as Java servers, use the JAVA_HOME environment variable to determine the Java installation location. To set this environment variable, we will first need to find out where Java is installed. You can do this by executing the same command as in the previous section:

    $sudo update-alternatives –config java

    Copy the path from your preferred installation and then open /etc/environment using nano or your favourite text editor.

    $sudo nano /etc/environment

    At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path.

    JAVA_HOME=”/usr/lib/jvm/java-8-oracle”

    Save and exit the file, and reload it.

    $ source /etc/environment

    You can now test whether the environment variable has been set by executing the following command:

    $echo $JAVA_HOME

    How To Uninstall Oracle Java 8 Application in Ubuntu 18.04?

    To Uninstall Oracle Java 8 Application from your system using the following command.

    $sudo apt-get purge oracle-java8-installer

    uninstall java

Jay Prakash Kumar
If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Facebook or Twitter. Jay Prakash is a founder of Professional Hacker, Technical Writer, Software Developer, Security Analyst and Technology Enthusiast with a keen eye on the Cyber-world and other technology-related developments.
https://professionalhacker.in/

One thought on “How to install-uninstall Oracle Java 8 on Ubuntu 18.04

Leave a Reply

Top