☕ Comprehensive Guide: Installing Java JDK on Your BrainHost VPS

Java remains the backbone of enterprise applications, modern microservices, and popular development frameworks like Spring Boot. This guide provides comprehensive instructions for installing the Java Development Kit (JDK) on your BrainHost VPS, ensuring you have the runtime and tools necessary for your development or production environment.

Alex Chen

Alex Chen

DevOps Engineer

Oct 24, 2025

8 min read

A detailed guide for BrainHost VPS users covering multiple ways to install the Java Development Kit (JDK), including quick installation via package managers (APT, YUM/DNF) and manual installation of official OpenJDK releases.

We provide two primary installation methods to suit different needs and Linux distributions:

  1. OpenJDK via Package Manager (Recommended): The fastest and easiest way to deploy the open-source JDK.
  2. Manual TAR.GZ Installation (Advanced): For strict version control, customized paths, or installing specific vendor builds (like Oracle, Adoptium, or Azul Zulu).

For the vast majority of Java applications, OpenJDK is a free, open-source, and fully compliant alternative to Oracle JDK. It is the fastest way to get Java running on your BrainHost VPS.

1. Debian/Ubuntu Systems (Using APT)

Execute the following commands as a sudo user on your BrainHost VPS. We will use Java 17 (a Long-Term Support, or LTS, version) as an example.

JDK VersionInstallation Command (LTS)
Java 17 (LTS)sudo apt install openjdk-17-jdk -y
Java 21 (LTS)sudo apt install openjdk-21-jdk -y
Java 8 (Legacy)sudo apt install openjdk-8-jdk -y

Example Installation for Java 17:

# Update the local package index
sudo apt update

# Install OpenJDK 17
sudo apt install openjdk-17-jdk -y

Verify the Installation:

java -version

You should see output similar to this:

openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-120.04, mixed mode, sharing)

2. RHEL/CentOS/Rocky/AlmaLinux Systems (Using DNF/YUM)

For RHEL-based distributions, the package names are slightly different. Use dnf on modern systems (CentOS 8+, RHEL 8+) or yum on older systems (CentOS 7).

JDK VersionInstallation Command (LTS)
Java 17 (LTS)sudo dnf install java-17-openjdk-devel -y
Java 21 (LTS)sudo dnf install java-21-openjdk-devel -y
Java 8 (Legacy)sudo dnf install java-1.8.0-openjdk-devel -y

Example Installation for Java 17:

# Install OpenJDK 17 Development Kit
sudo dnf install java-17-openjdk-devel -y

Verify the Installation:

java -version

II. 🛠️ Method 2: Manual TAR.GZ Installation (Advanced)

Manual installation is necessary when you need to install a non-default JDK version, a specific vendor build (e.g., Adoptium, Oracle), or deploy Java to a non-standard path on your BrainHost VPS.

Step 1: Download the JDK Archive

First, visit the official website of your chosen JDK vendor (e.g., Oracle, Adoptium) and download the required Linux x64 tar.gz file.

For this example, we assume you download a file named jdk-21_linux-x64_bin.tar.gz.

# Change to a temporary directory
cd /tmp

# Use wget to download (REPLACE WITH THE ACTUAL DOWNLOAD LINK)
# sudo wget [JDK_DOWNLOAD_URL] -O jdk-21.tar.gz

Step 2: Extract to the Installation Directory

Create a dedicated directory to store all your Java versions, typically /usr/lib/jvm/.

# Create the standard Java installation directory
sudo mkdir -p /usr/lib/jvm

# Extract the archive into the directory
# (Replace 'jdk-21_linux-x64_bin.tar.gz' with your file name)
sudo tar -xzf jdk-21_linux-x64_bin.tar.gz -C /usr/lib/jvm/

# List the directory to find the extracted folder name (e.g., jdk-21)
ls /usr/lib/jvm/

Step 3: Configure System Environment Variables

To ensure the system and all users recognize the new JDK path, you must set the PATH and, crucially, the JAVA_HOME environment variables.

  1. Set JAVA_HOME Globally:
    Edit the /etc/profile file for system-wide configuration:
    sudo nano /etc/profile
    

    Append the following lines to the end of the file, replacing jdk-21 with your actual extracted folder name:
    # Set JAVA_HOME for BrainHost VPS
    export JAVA_HOME=/usr/lib/jvm/jdk-21
    export PATH=$PATH:$JAVA_HOME/bin
    
  2. Apply the Configuration:
    source /etc/profile
    

Step 4: Use update-alternatives (Debian/Ubuntu/RHEL)

The update-alternatives command is a convenient way to manage multiple installations of the same utility (like java) and switch between them easily.

# Register the new Java executable (priority '1' is arbitrary here)
# Replace 'jdk-21' with your directory name
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-21/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-21/bin/javac 1

# Select the default Java version
sudo update-alternatives --config java

Verify the Installation:

echo $JAVA_HOME
java -version

III. ✅ Final Verification and Version Management

1. Final Checks

Regardless of the method used, these checks ensure Java is correctly set up on your BrainHost VPS:

# Check if JAVA_HOME is set (Crucial for build tools like Maven/Gradle)
echo $JAVA_HOME

# Check the path of the 'java' executable
which java

2. Switching Between Java Versions

If you have multiple JDKs installed, you can easily switch the active version:

For package manager and update-alternatives installations:

# Lists all registered Java versions and prompts you to select the default one
sudo update-alternatives --config java

For manual installations:

To switch, you must manually edit the /etc/profile file (or your user's ~/.bashrc) and change the JAVA_HOME path, followed by executing source /etc/profile to reload the configuration.


Your BrainHost VPS is now successfully equipped with the Java JDK! You are ready to deploy your Java-based applications or build systems.

Tags

JavaJDKVPSLinuxProgrammingBrainHost
Alex Chen

Alex Chen

DevOps Engineer

DevOps Engineer specializing in cloud infrastructure and automation.

BrainHost - A reliable VPS hosting platform offering high-performance virtual servers with advanced management capabilities.

[email protected]

© 2025 BrainHost. All rights reserved.