Java is a widely used programming language and platform that’s essential for running various software and applications. This guide will walk you through the process of installing Java on Ubuntu 18.04.
Before you begin, ensure that your Ubuntu system is up to date by running the following commands:
sudo apt update
sudo apt upgrade
Ubuntu 18.04 includes OpenJDK by default, which is an open-source version of Java. You can install OpenJDK 8 (a long-term support version) with the following command:
sudo apt install openjdk-8-jdk
Adding the Oracle JDK Repository:
If you prefer to use Oracle’s JDK, you can add the Oracle JDK repository and install it. Be aware that Oracle’s JDK has a different licensing model, and you may need to accept the license agreement during installation. To add the Oracle JDK repository and install it, follow these steps:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
To install Oracle JDK 11 (a stable version), use this command:
sudo apt install oracle-java11-installer
Setting Up JAVA_HOME:
To set up the
JAVA_HOME environment variable, follow these steps:
- Open your
~/.bashrcfile in a text editor:
- Add the following line at the end of the file, replacing
/usr/lib/jvm/java-11-oraclewith the actual path to your Oracle JDK installation:
- Save the file and exit the text editor.
- Source your
.bashrcfile to apply the changes:
You can verify that Java has been installed correctly and that the
JAVA_HOME variable is set correctly by running the following commands:
These commands should display the Java version and the path to your Java installation.
By following these steps, you’ll have Java installed and configured on your Ubuntu 18.04 system. Make sure to choose the Java version that best suits your needs and application requirements.