
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
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
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
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
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
$ java -version
You can also open and check the java application graphically using Search your Ubuntu Applications box. Refer to the snapshot below.
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
Excellent web site you have here.. It’s difficult to find good quality writing
like yours nowadays. I truly appreciate people like you! Take
care!!