Magazine

How to Install and Uninstall Java on Ubuntu

Posted on the 23 March 2023 by Top10

In the world of software development, Java is one of the most used programming languages. You can use it to develop websites, software, android apps, and even games.

But first of all, you need to install Java on your computer. Most Linux distributions do not have Java pre-installed and users have to manually install it on their system.

JDK vs JRE: which one to choose?

When you first get started with Java, the acronyms JDK, JRE, and JVM are the ones that confuse you the most.

  1. JDK (Java Development 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 applications built in Java while JDK is used to develop Java applications.

The JRE includes the JVM and some class libraries that enable your system to run Java applications. The JVM acts like a virtual machine that creates an environment for running Java on your computer.

On the other hand, the JDK includes a JRE and some additional development tools that allow you to use class libraries to develop your own applications.

In general, if you only want to run Java applications like Minecraft on your system, you will need the Java Runtime Environment. If your ultimate goal is to learn Java and develop software, then you should install the Java Development Kit.

Versions and implementations of Java

Now that you've decided what you want to download, it's time to get some practice and get started installing Java on Ubuntu.

Java has several editions 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 be downloading the standard version of Java, i.e. Java SE.

As with the various Java platforms, there are several implementations of Java that you can install on your system. The Ubuntu repositories provide an open source Java implementation known as OpenJDK and OpenJRE. Oracle Java is another implementation you can download, however it is mainly used for commercial purposes.

Since the current version of Java LTS (Long Term Support) is Java 17, this tutorial will focus on it. You can download other versions of Java for free if you like.

Install OpenJDK and OpenJDK on Ubuntu

You can install OpenJDK on Ubuntu using the terminal. To do this, you will have to use APT, which is the default package manager pre-installed on Debian-based Linux distributions.

  1. Launch a terminal by pressing Ctrl + Alt + T and update your system's package list:
    sudo apt update
  2. Enter the following command to download OpenJDK:
    sudo apt install default-jdk
  3. Type y and press Enter to confirm the installation.

Similarly, you can install OpenJDK on your system with:

sudo apt install default-jre

Verify that Java has been successfully installed by typing java -version in a terminal. If the output shows version information related to Java packages, then Java has been successfully installed on your system.

Download and Install Oracle Java on Ubuntu

The Ubuntu repositories do not provide the Oracle Java package. However, you can download the Oracle Java package from the official website.

Download: Oracle Java

Follow the steps below to install Oracle Java on Ubuntu:

  1. Go to the Oracle Java download web page.
  2. Go to the Java 17 (LTS) download section by clicking on the appropriate option.
  3. Click on the URL next to the "x64 Debian Package" option to download the package.

The website may ask 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, navigate to the folder where you saved the DEB file. Double click the file to launch the Snap Store. If that doesn't work, right-click the file and select Open with another application > Install Software.

When the Snap Store window appears, click the Install button to begin installing Oracle Java on your system.

Add Java to Environment Variables

If you installed Oracle Java from the official website, you will have to manually set the Java PATH variable on your system.

  1. Run the below command in your terminal. Be sure to enter the Java path exactly as it appears on your system.
    export JAVA_HOME=/usr/lib/jvm/jdk-17
  2. Verify that the path was set successfully by printing out the value of JAVA_HOME using echo. The Java directory will be displayed in the output.
    echo $JAVA_HOME
  3. Add the Java /bin directory to your PATH variable with:
    export PATH=$PATH:$JAVA_HOME/bin
  4. Make sure Java PATH is set correctly by running:
    java --version

The output will display information related to the current version of Java.

How to remove Java from Ubuntu

When you are done with Java, you can easily uninstall it in Ubuntu. To uninstall OpenJDK and OpenJRE, launch a terminal with Ctrl + Alt + T and enter the following command to remove Java from your system:

sudo apt remove default-jdk default-jre

Confirm the deletion process by entering y. OpenJDK and OpenJRE will be automatically removed from your computer.

For those who have installed the Oracle JDK, there are two ways to uninstall Java. You can double-click the DEB package file to open the Snap Store and then click the Uninstall button to remove the package.

Alternatively, you can remove the package using the system terminal:

  1. Get the JDK package name using dpkg and grep.
    dpkg --list | grep jdk
  2. Then remove the package with APT. Don't forget to replace the package name with the output of the previous command.
    sudo apt remove jdk-17
  3. Type y and press Enter to remove the package.

Managing a Java installation on Ubuntu

While some Linux distributions, such as Arch Linux, come with Java pre-installed, most do not. If you are running 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 is now much easier. JDBC (Java Database Connectivity) is a component of the Java SDK that allows you to securely add, delete, update, and store records.

2626020cookie-checkHow to install and uninstall Java on Ubuntuno

similar

Инструкции,Программы,java,ubuntu,инструкции,программы,установка
#Install #Uninstall #Java #Ubuntu


Back to Featured Articles on Logo Paperblog