openSUSE

How To Install Java on openSUSE

Install Java on openSUSE

In this tutorial, we will show you how to install Java on openSUSE. Java, a high-level programming language, was developed by Sun Microsystems, which is now part of Oracle. It comprises two main components: the Java Runtime Environment (JRE) and the Java Development Kit (JDK). The JRE includes the Java Virtual Machine (JVM) and the necessary libraries to run Java programs, while the JDK provides tools for developing, testing, and debugging Java applications.

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 Java on openSUSE.

Prerequisites

  • A server running one of the following operating systems: openSUSE.
  • 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 to download Java and its dependencies.
  • You have access to a user account with sudo or root privileges.

Install Java on openSUSE

Step 1. Firstly, we need to ensure that our openSUSE system is up-to-date. Open the terminal by pressing Ctrl + Alt + T or by searching for ‘terminal’ in the application menu. Once the terminal is open, execute the following command to update the system:

sudo zypper refresh
sudo zypper update

Step 2. Installing Java on openSUSE.

To install Java on openSUSE, you need to download the correct RPM package from Oracle’s website. Go official page and select the RPM package for your system architecture. For instance, if you have a 64-bit system, download the x64 RPM file. Save the RPM file to your home directory or a location where you can easily access it.

wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.rpm

Now install Java using the rpm command:

sudo rpm -ivh jdk-21_linux-x64_bin.rpm

To check that Java is correctly installed, run:

java -version

You should also see Java in the command path:

which java

Step 3. Setting the JAVA_HOME Environment Variable.

 Next, set the JAVA_HOME environment variable to point to the directory where the JDK was installed. This is typically /usr/lib/jvm/jdk-21. You can set this variable in your shell’s profile file (like ~/.bashrc or ~/.bash_profile for the Bash shell) with the following command:

export JAVA_HOME=/usr/lib/jvm/jdk-21

 This command sets the JAVA_HOME variable to the JDK installation directory.

Then, update the PATH environment variable to include the bin directory of the JDK installation. This allows the system to find the Java and Java Compiler (javac) executables. You can do this with the following command:

export PATH=$PATH:$JAVA_HOME/bin

 Finally, apply the changes to the current shell session with the following command:

source ~/.bashrc

 Or, if you used ~/.bash_profile:

source ~/.bash_profile

Verify that the environment variables have been set correctly by checking the Java version:

java -version

Step 4. Testing the Java Installation.

Test the installation by compiling and running a simple Java program. Create a file named HelloWorld.java with the following content:

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

Compile the program using the command javac HelloWorld.java and run it using the command java HelloWorld. If the message “Hello, World!” is displayed, the installation was successful.

Congratulations! You have successfully installed Java. Thanks for using this tutorial for installing Java on your openSUSE system. For additional or useful information, we recommend you check the official Java 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 a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button