Introduction
Glad you’ve joined us for this complete tutorial on Installing Java on Ubuntu. By the conclusion of this extensive guide, you’ll grasp the procedure and execute it without difficulty.
Grasping the Concept of Java
Prior to diving into the steps, it’s vital to comprehend what Java is. Java is a general-purpose, concurrent, class-based, and object-oriented programming language. It’s fashioned to be as dependency-free as possible, enabling application developers to “write once, run anywhere” (WORA).
The Need to Install Java on Ubuntu
You might wonder, why is it necessary to install Java on Ubuntu? The rationale is straightforward. Numerous applications and software are designed using Java, hence installing it can broaden your Ubuntu system’s utility range.
Diverse Java Versions
Several versions of Java exist, but the most prevalent ones are:
-
Java Standard Edition (Java SE): This is the fundamental Java programming platform. It encompasses all the core APIs essential for any Java developer.
-
Java Enterprise Edition (Java EE): This version expands the Java SE and is utilized for server-based applications such as websites and substantial enterprise applications.
-
Java Micro Edition (Java ME): It’s a subset of the Java SE and is deployed for developing applications that run on resource-limited devices like mobile phones.
Varieties of Java: OpenJDK versus Oracle JDK
JDK has two principal implementations: OpenJDK and Oracle JDK. OpenJDK is an open-source variant of the Java Platform, whereas Oracle JDK is a commercially supported version by Oracle. Both can execute Java applications, though minor differences may exist.
Now, let’s shift our focus to this guide’s main topic – Installing Java on Ubuntu.
The Procedure for Installing Java on Ubuntu
Java installation on Ubuntu can be achieved in two ways:
- Installation of Default JDK/JRE on Ubuntu
- Installation of a Specific Version of OpenJDK
We’ll now delve into each method.
1. Installation of Default JDK/JRE on Ubuntu
Installing Java using the Ubuntu-packaged version is the simplest option. Follow these steps:
-
Firstly, update the package index by entering this command in your terminal:
sudo apt update
-
Verify if Java is already installed:
java -version
If it returns “The program java can be found in the following packages”, it means Java hasn’t been installed yet, and you can proceed to the next step.
-
To install the Default JDK (Java Development Kit), use this command:
sudo apt install default-jdk
This command also installs the Java Runtime Environment (JRE).
- Installation of a Specific Version of OpenJDK
If you desire a specific OpenJDK version, follow these instructions:
-
Update the package index with this command:
sudo apt update
-
You can view the available versions with this command:
apt search openjdk
-
You can install your preferred version with this command:
sudo apt install openjdk-[version]-jdk
Replace [version] with your desired version number.
Verification of Java Installation
After Java installation, it’s crucial to confirm its success. Use this command:
java -version
Setting up the JAVA_HOME Environment Variable
Several programs, like Apache Maven, utilize the JAVA_HOME
environment variable to ascertain the Java installation location. To set this environment variable, first identify your Java installation path with this command:
sudo update-alternatives --config java
Copy your preferred installation’s path and open /etc/environment
using nano or your text editor of choice.
sudo nano /etc/environment
Add the following line at this file’s end, ensuring to substitute the highlighted path with your copied path.
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Save the file and exit. To effect these changes, either reboot your system or execute the following source command:
source /etc/environment
Conclusion
Congratulations! You’ve successfully completed Installing Java on Ubuntu. You’re now ready to commence Java development or run Java apps. If you encounter any installation issues, most can be resolved by revisiting your steps. Happy programming!