In the world of software development, Java is one of the most widely used programming languages. You can use it to develop websites, desktop software, Android applications, and even games.
Before doing this, however, you must first install Java on your computer. Most Linux distributions do not have Java pre-installed and users have to manually install it on their system.
In this article we are going to cover installing and removing Java on Ubuntu as well as a detailed section on JDK and JRE.
JDK vs JRE: Which Should You Choose?
When you first start out with Java, abbreviations such as JDK, JRE, and JVM will confuse you the most.
- JDK (Java developer kit)
- JRE (Java runtime environment)
- JVM (Java virtual machine)
The main difference between JDK and JRE is that JRE is used to run Java-based applications, while JDK is used to develop Java applications. JRE includes JVM and some class libraries that your system can use to run Java applications. JVM acts as a virtual machine that creates an environment on your computer to run Java.
On the other hand, JDK includes JRE and some additional development tools that allow you to use the class libraries to develop your own applications.
All in all, if you only want to run Java applications on your system, such as: B. Minecraft. If your end goal is development and you want to dip your hands in programming, the Java Development Kit is required.
How to install Java on Ubuntu
Now that you've decided what to download, it's time to get handy and install Java on your Ubuntu computer.
Java has several platforms available for download.
Java Standard Edition (Java SE)
Java Micro Edition (Java ME)
Java Enterprise Edition (Java EE)
For this article, we will download the standard version of Java, i. H. Java SE.
As with the various Java platforms, there are several Java implementations that you can install on your system. Ubuntu repositories provide an open source Java implementation known as the Open JDK and Open JRE. Oracle Java is another implementation that you can download. However, it is mainly used commercially.
Since the current Long-Term Support (LTS) version of Java is Java 11, this guide will focus on the same thing. You can download other versions of Java to your system if you want.
Install OpenJDK and OpenJRE
OpenJDK can be installed via the terminal on Ubuntu. Use apt for this process. This is the standard package manager that comes pre-installed in Debian-based distributions.
Start the terminal by pressing Ctrl + Old + T. on the keyboard.
Update your system's package list.
sudo apt-get update
Enter the following command to download OpenJDK.
sudo apt install default-jdk
Type in y and press Enter to confirm the installation.
You can also install Open JRE on your system:
sudo apt install default-jre
Check by typing whether Java has been successfully installed on your system Java version in the terminal. If the output shows version information about the Java packages, Java was successfully installed on your system.
Download and install Oracle Java
The Ubuntu repositories do not offer the official Oracle Java package. Hence, you need to add third party repositories to download them.
Open the terminal by pressing Ctrl + Old + T..
Enter the following command to get the add-apt-repository Utility on your system.
sudo apt install software-properties-common
There are two repositories that provide the Oracle Java package. Add one of the two PPA repositories to your system.
sudo add-apt-repository ppa: webupd8team / java
sudo add-apt-repository ppa: linuxuprising / java
Update your system's package list with suitable.
sudo apt-get update
Install Oracle Java 11 on your system.
sudo apt install oracle-java11-installer-local
You can also download the Oracle Java package from the Oracle official website. In order to do this:
Visit the Oracle Java download website.
Scroll down until you find this one Java SE 11 (LTS) Download area.
click on Download JDK Possibility.
Download the Linux x64Debian package from the list of available downloads.
Check the I have reviewed and accepted the Oracle Technology Network license agreement for Oracle Java SE Possibility.
click Download to get the package.
Notice that the website asks you to sign in to your Oracle account. If you don't have an account, you can create one for free. As soon as you log into your account, the download will start automatically.
To install the Oracle Java package you just downloaded, go to the location where you saved this .deb File. Double-click the file to start Ubuntu Software center. click on To install Click the button to start installing Oracle Java on your system.
Add Java to the environment variables
If you installed Oracle Java from the official website, you will need to manually set the Java PATH variable on your system.
Find the directory where Java is installed on your local storage.
Where is java?
Enter the following command in your terminal. Replace Path / to / Java with the output of the previous command.
export JAVA_HOME = / path / to / java
Check if the JAVA_HOME Path was established successfully. The Java directory is shown in the output.
echo $ JAVA_HOME
Add the Java /Container Directory for PATH Variable.
export PATH = $ PATH: $ JAVA_HOME / bin
Make sure the Java path is configured correctly.
The output shows information about the current version of Java on your system.
Remove Java from Ubuntu
Once you are done with Java, you can simply uninstall it from Ubuntu. To remove OpenJDK and OpenJRE:
Start the terminal with Ctrl + Old + T..
Enter the following command to remove Java from your system.
sudo apt remove default-jdk default-jre
Confirm the uninstallation process by entering y.
OpenJDK and OpenJRE are automatically removed from your computer.
For those who have the Oracle JDK installed, there are two ways to uninstall Java. You can double click on that .deb Open package file Software center and then click Remove Uninstall the package button.
Alternatively, you can remove the package via your system terminal.
Open the Terminal on Ubuntu.
Get the JDK package name with dpkg and grep.
dpkg –list | grep jdk
Uninstall the package with suitable. Replace the package name with the output from the previous command.
sudo apt remove jdk-11.0.10
Art y and press Enter to continue the uninstallation process.
Manage the Java installation on Ubuntu
While some Linux distributions like Arch Linux come with Java preinstalled, most don't. If you're using Ubuntu on your computer, you might not be able to run Java applications right away. You have to manually install Java on your system.
Integrating a database into your Java application is now much easier. JDBC Java Database Connectivity is a component of the Java SDK that enables you to securely add, delete, update, and save records of information.
How to connect to a MySQL database using Java
Java offers JDBC as part of the Java SDK. In this article, we'll look at the details of how to connect to a MySQL database and run queries.
About the author
(34 articles published)
Deepesh is the junior editor for Linux at MUO. He has been writing informational content on the Internet for over 3 years. In his spare time he enjoys writing, listening to music and playing the guitar.
From Deepesh Sharma
Subscribe to our newsletter
Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive deals!
One more step …!
Please confirm your email address in the email we just sent you.