How to Install Java on Ubuntu and Remove It When You’re Done
Reading Time: 4 minutesNeed to install Java on your Ubuntu system? Whether you’re coding in Java or using an app, here’s how to get it running.
In the world of software development, Java is one of the most widely used programming languages. You can use it for developing websites, desktop software, Android applications, and even games.
But before all that, the first thing you need to do is install Java on your machine. Most Linux distributions do not have Java preinstalled and users have to install it manually on their system.
Here’s how to install and remove Java on Ubuntu, along with a detailed section on JDK and JRE.
JDK vs. JRE: Which One Should You Choose?
When you first start with Java, abbreviations such as JDK, JRE, and JVM will confuse you the most.
- JDK (Java Development Kit)
- JRE (Java Runtime Environment)
- JVM (Java Virtual Machine)
The primary difference between JDK and JRE is that JRE is used to run applications built on Java, while JDK is used to develop Java applications.
JRE includes JVM and some class libraries that allow your system to run Java apps. JVM acts as a virtual machine that creates an environment for running Java on your computer.
On the other hand, JDK includes JRE and some additional development tools that allow you to use the class libraries for developing your own applications.
All in all, if you only want to run Java applications on your system, like Minecraft, you’ll need Java Runtime Environment. If your end goal is to learn Java and develop software, then you should install Java Development Kit.
Java Editions and Implementations
Now that you’ve decided what you want to download, it is time to get practical and start installing Java on Ubuntu.
Java has several editions that are available to download.
- Java Standard Edition (Java SE)
- Java Micro Edition (Java ME)
- Java Enterprise Edition (Java EE)
- JavaFX
For this article, we will be downloading the standard edition of Java, i.e. Java SE.
Like the different Java platforms, there are several Java implementations you can install on your system. Ubuntu repositories provide an open-source Java implementation known as OpenJDK and OpenJRE. Oracle Java is another implementation that you can download, however, it’s mostly used commercially.
Since the current LTS (Long-Term Support) version of Java is Java 17, this guide will focus on the same. You are free to download other versions of Java if you want.
Install OpenJDK and OpenJRE on Ubuntu
You can install OpenJDK on Ubuntu using the terminal. You’ll have to use APT for this process, which is the default package manager that comes preinstalled in Debian-based Linux distributions.
- Launch the terminal by pressing Ctrl + Alt + T and update your system’s package list with:
sudo apt update
- Issue the following command to download OpenJDK:
sudo apt install default-jdk
- Type y and press Enter to confirm the installation.
Similarly, you can install OpenJRE on your system with:
sudo apt install default-jre
Verify if Java was successfully installed by typing java –version in the terminal. If the output displays version information associated with the Java packages, then Java is successfully installed on your system.
Download and Install Oracle Java on Ubuntu
The Ubuntu repositories do not provide the Oracle Java package. You can download the Oracle Java package from the official website, however.
Download: Oracle Java
Follow the steps below to install Oracle Java on Ubuntu:
- Head over to the Oracle Java Download webpage.
- Switch to the Java 17 (LTS) download section by clicking on the corresponding option.
- Click on the URL next to the x64 Debian Package option to download the package.
To install the Oracle Java package you just downloaded, go to the location where you saved the DEB file. Double-click on the file to launch Snap Store. If that doesn’t work, right-click the file and click Open With Other Application > Software Install.
When the Snap Store window pops up, click the Install button to start installing Oracle Java on your system.
Add Java to the Environment Variables
If you have installed Oracle Java from the official website, you will have to manually set the Java PATH variable on your system.
- Issue the below-given command in your terminal. Make sure to enter the Java path exactly as it appears on your system.
export JAVA_HOME=/usr/lib/jvm/jdk-17
- Verify if the path was set up successfully by printing the value of JAVA_HOME using echo. The Java directory will be displayed in the output.
echo $JAVA_HOME
- Add the Java /bin directory to the PATH variable with:
export PATH=$PATH:$JAVA_HOME/bin
- Ensure that the Java PATH is properly configured by running:
java --version
The output will display information related to the current version of Java.
How to Remove Java From Ubuntu
Once you’re done with Java, you can easily uninstall it on Ubuntu. To remove OpenJDK and OpenJRE, launch the terminal using Ctrl + Alt + T and issue the following command to remove Java from your system:
sudo apt remove default-jdk default-jre
Confirm the uninstallation process by typing y. OpenJDK and OpenJRE will be automatically removed from your computer.
For those who have installed Oracle JDK, there are two ways to uninstall Java. You can double-click the DEB package file to open Snap Store and then click the Remove button to uninstall the package.
Alternatively, you can remove the package using your system terminal:
- Get the JDK package name using dpkg and grep.
dpkg --list | grep jdk
- Then, uninstall the package using APT. Remember to replace the package name with the output of the previous command.
sudo apt remove jdk-17
- Type y and hit Enter to uninstall the package.
Managing Java Installation on Ubuntu
While some Linux distributions like Arch Linux come with Java preinstalled, a majority of them don’t. If you are using Ubuntu on your computer, chances are you won’t be able to run Java applications right away. You will have to install Java manually on your system.
Integrating a database with your Java application has become a lot easier now. JDBC (Java Database Connectivity) is a component of the Java SDK that allows you to add, delete, update, and store records securely.
Reference: https://www.makeuseof.com/install-java-ubuntu/
Ref: makeuseof
MediaDownloader.net -> Free Online Video Downloader, Download Any Video From YouTube, VK, Vimeo, Twitter, Twitch, Tumblr, Tiktok, Telegram, TED, Streamable, Soundcloud, Snapchat, Share, Rumble, Reddit, PuhuTV, Pinterest, Periscope, Ok.ru, MxTakatak, Mixcloud, Mashable, LinkedIn, Likee, Kwai, Izlesene, Instagram, Imgur, IMDB, Ifunny, Gaana, Flickr, Febspot, Facebook, ESPN, Douyin, Dailymotion, Buzzfeed, BluTV, Blogger, Bitchute, Bilibili, Bandcamp, Akıllı, 9GAG