The cart is empty

Java stands as one of the most widely used programming languages globally, finding applications in a broad spectrum from mobile apps to large-scale enterprise systems. For server administrators, it's crucial to know how to properly install and configure Java Runtime Environment (JRE) or Java Development Kit (JDK) on a server to run and develop Java applications. This article will guide you through the step-by-step process of installing Java on a server.

Prerequisites

Before initiating the installation, ensure your server meets the following prerequisites:

  • Access to the server with superuser (root) privileges.
  • Adequate disk space for installing and running Java applications.
  • Active internet connection to download necessary files.

Step 1: Update System

Prior to installing any new software, it's recommended to update the system to ensure it's secure and compatible with the latest packages. For Debian or Ubuntu-based systems, use the commands:

sudo apt update
sudo apt upgrade

For CentOS or RHEL-based systems, use:

sudo yum update

Step 2: Download Java

There are two main distributions of Java that you can install on the server: OpenJDK and Oracle JDK. OpenJDK is an open-source and freely available JDK, while Oracle JDK may require a license depending on your usage.

To install OpenJDK, use for Debian/Ubuntu:

sudo apt install openjdk-11-jdk

For CentOS/RHEL:

sudo yum install java-11-openjdk-devel

Replace 11 with the Java version you wish to install.

Step 3: Verify Installation

After the installation is complete, verify that Java has been installed correctly by running

java -version

This command will display the installed Java version, confirming a successful installation.

Step 4: Set JAVA_HOME Environment Variable

Some applications require the JAVA_HOME environment variable to determine the Java installation. Set this variable by finding the path to your Java installation and adding an export to your ~/.bashrc or ~/.profile file for Bash or to ~/.zshrc for Zsh:

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

Replace the path with the correct path to your Java installation.

 

You should now have Java installed and correctly configured on your server. You can start developing and running Java applications on your server. Remember to regularly update your Java installation to keep it secure and stable.