The best way to Set up Java on Ubuntu and Take away it When You are Executed

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.

  1. JDK (Java developer kit)
  2. JRE (Java runtime environment)
  3. 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.

  1. Java Standard Edition (Java SE)

  2. Java Micro Edition (Java ME)

  3. Java Enterprise Edition (Java EE)

  4. JavaFX

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.

Related topics: Learn how to create classes in Java

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.

  1. Start the terminal by pressing Ctrl + Old + T. on the keyboard.

  2. Update your system's package list.
    sudo apt-get update

  3. Enter the following command to download OpenJDK.
    sudo apt install default-jdk

  4. 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.

  1. Open the terminal by pressing Ctrl + Old + T..

  2. Enter the following command to get the add-apt-repository Utility on your system.
    sudo apt install software-properties-common

  3. 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

  4. Update your system's package list with suitable.
    sudo apt-get update

  5. 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:

  1. Visit the Oracle Java download website.

  2. Scroll down until you find this one Java SE 11 (LTS) Download area.

  3. click on Download JDK Possibility.

  4. Download the Linux x64Debian package from the list of available downloads.

  5. Check the I have reviewed and accepted the Oracle Technology Network license agreement for Oracle Java SE Possibility.

  6. 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.

  1. Find the directory where Java is installed on your local storage.
    Where is java?

  2. Enter the following command in your terminal. Replace Path / to / Java with the output of the previous command.
    export JAVA_HOME = / path / to / java

  3. Check if the JAVA_HOME Path was established successfully. The Java directory is shown in the output.
    echo $ JAVA_HOME

  4. Add the Java /Container Directory for PATH Variable.
    export PATH = $ PATH: $ JAVA_HOME / bin

  5. Make sure the Java path is configured correctly.
    Java version

The output shows information about the current version of Java on your system.

Related: Best Beginner Projects For New Programmers

Remove Java from Ubuntu

Once you are done with Java, you can simply uninstall it from Ubuntu. To remove OpenJDK and OpenJRE:

  1. Start the terminal with Ctrl + Old + T..

  2. Enter the following command to remove Java from your system.
    sudo apt remove default-jdk default-jre

  3. 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.

  1. Open the Terminal on Ubuntu.

  2. Get the JDK package name with dpkg and grep.
    dpkg –list | grep jdk

  3. Uninstall the package with suitable. Replace the package name with the output from the previous command.
    sudo apt remove jdk-11.0.10

  4. 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.

Continue reading

About the author

Deepesh Sharma
(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.

Leave a Reply

Your email address will not be published. Required fields are marked *