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
DevOps Engineer
Oct 24, 2025
8 min read

We provide two primary installation methods to suit different needs and Linux distributions:
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.
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 Version | Installation 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)
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 Version | Installation 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
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.
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
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/
To ensure the system and all users recognize the new JDK path, you must set the PATH and, crucially, the JAVA_HOME environment variables.
JAVA_HOME Globally:/etc/profile file for system-wide configuration:sudo nano /etc/profile
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
source /etc/profile
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
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
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
Alex Chen
DevOps Engineer
DevOps Engineer specializing in cloud infrastructure and automation.
Related Articles

Complete Guide: Installing Nginx on Your BrainHost VPS
A step-by-step guide for engineers to install the Nginx web server on a BrainHost VPS, covering both quick installation using package managers (APT/YUM) and advanced compilation from source for custom modules and optimized performance.

Practical VPS Guide for Engineers: From Hobby to Production
A comprehensive guide for engineers covering VPS fundamentals, virtualization stack, practical use cases, best practices for networking, storage, security, and building a production-ready system.

Rapid WordPress Deployment with Docker Compose on High-Performance KVM VPS
A comprehensive guide to deploying a full containerized WordPress stack (Nginx, PHP-FPM, MySQL, Certbot) using Docker Compose on a high-performance KVM VPS, featuring automated HTTPS setup.
BrainHost - A reliable VPS hosting platform offering high-performance virtual servers with advanced management capabilities.