openSUSE

How To Install OpenJDK on openSUSE

Install OpenJDK on openSUSE

In this tutorial, we will show you how to install OpenJDK on openSUSE. OpenJDK is the open-source implementation of the Java Platform, Standard Edition (Java SE). It provides developers with the tools necessary to create, compile, and run Java applications. Unlike Oracle’s proprietary JDK, OpenJDK is freely available and maintained by the open-source community.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the OpenJDK on openSUSE.

Prerequisites

  • A server running one of the following operating systems: openSUSE (Leap or Tumbleweed)
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • You will need access to the terminal to execute commands. openSUSE provides the Terminal application for this purpose. It can be found in your Applications menu.
  • You’ll need an active internet connection.
  • You’ll need administrative (root) access or a user account with sudo privileges.

Install OpenJDK on openSUSE

Step 1. Update System Packages.

Before installing OpenJDK, it’s crucial to ensure your openSUSE system is up-to-date and properly configured. Follow these steps to prepare your system:

sudo zypper refresh
sudo zypper update

The zypper refresh command refreshes the repository cache, while zypper update upgrades all installed packages to their latest available versions. This process may take a few minutes, depending on the number of updates available and your internet connection speed.

Step 2. Installing OpenJDK.

Now that your system is prepared, let’s proceed with installing OpenJDK. There are multiple methods to install OpenJDK on openSUSE, including using the official repositories, installing multiple versions, and using Snap packages.

  • Using the Official Repositories.

The easiest and recommended method to install OpenJDK is through openSUSE’s official repositories. Follow these steps:

sudo zypper search java-*-openjdk

Choose the version you want to install (e.g., Java 11) and run:

sudo zypper install java-11-openjdk

After the installation completes, verify it by running:

java -version

You should see the version information for the installed OpenJDK.

  • Installing Multiple OpenJDK Versions.

For developers who need to work with different Java versions, it’s possible to install multiple OpenJDK versions side by side. Here’s how:

sudo zypper install java-1_8_0-openjdk
sudo zypper install java-11-openjdk
sudo zypper install java-latest-openjdk

Use the update-alternatives command to switch between installed Java versions:

sudo update-alternatives --config java

Follow the on-screen prompts to select your desired version.

  • Installing OpenJDK using Snap

Snap is a universal package manager that works across many Linux distributions, including openSUSE. To install OpenJDK using Snap:

sudo zypper install snapd

Enable and start snapd services:

sudo systemctl enable --now snapd
sudo systemctl enable --now snapd.apparmor

Install OpenJDK via Snap:

sudo snap install openjdk

Verify the installation:

snap run openjdk.java --version

Step 3. Configuring Java Environment.

After installing OpenJDK, it’s important to configure your Java environment correctly. This ensures that your system uses the right Java version and that Java applications can find the necessary files.

  • Setting the Default Java Version

If you’ve installed multiple Java versions, you can set the default version using the update-alternatives command:

sudo update-alternatives --config java

Select the number corresponding to your preferred Java version from the list provided.

  • Configuring JAVA_HOME Environment Variable

Many Java applications rely on the JAVA_HOME environment variable. To set it:

update-alternatives --display java

Edit your shell configuration file, For Bash users, edit ~/.bashrc:

nano ~/.bashrc

Add the following line at the end of the file:

export JAVA_HOME=/path/to/your/java/installation

Replace “/path/to/your/java/installation” with the actual path.

Apply the changes:

source ~/.bashrc

Step 4. Testing the Java Installation.

After installation and configuration, it’s crucial to test your Java setup to ensure everything is working correctly.

Check the Java version:

java -version

Create a file named HelloWorld.java with the following content:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, idroot OpenSUSE!");
    }
}

Compile and run the program:

javac HelloWorld.java
java HelloWorld

If everything is set up correctly, you should see “Hello, idroot OpenSUSE!” printed to the console.

Congratulations! You have successfully installed OpenJDK. Thanks for using this tutorial for installing OpenJDK on your openSUSE system. For additional or useful information, we recommend you check the official OpenJDK website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button