Install Java (JDK/JRE)

01

Linux (Ubuntu/Debian)

OpenJDK (recommended, free)

bash
# Update packages
sudo apt update

# Java 21 LTS (current recommended version)
sudo apt install openjdk-21-jdk -y

# Java 17 LTS (very common, Minecraft, Spring Boot, etc.)
sudo apt install openjdk-17-jdk -y

# Java 11 LTS (legacy)
sudo apt install openjdk-11-jdk -y

# JRE only (runtime, without compiler: lighter)
sudo apt install openjdk-21-jre -y

Verify:

bash
java -version
javac -version  # only if you installed JDK

Manage multiple versions with update-alternatives

bash
# See installed versions
sudo update-alternatives --list java

# Change default version
sudo update-alternatives --config java
# A menu will appear: enter the number of the desired version

Configure JAVA_HOME

bash
# Find the path of the active version
readlink -f $(which java) | sed 's|/bin/java||'
# Example output: /usr/lib/jvm/java-21-openjdk-amd64

# Add to /etc/environment (all sessions, all users)
echo 'JAVA_HOME="/usr/lib/jvm/java-21-openjdk-amd64"' | sudo tee -a /etc/environment
echo 'PATH="$PATH:$JAVA_HOME/bin"' | sudo tee -a /etc/environment

# Apply to current session
source /etc/environment
echo $JAVA_HOME

Or for current user only (~/.bashrc):

bash
echo 'export JAVA_HOME="/usr/lib/jvm/java-21-openjdk-amd64"' >> ~/.bashrc
echo 'export PATH="$PATH:$JAVA_HOME/bin"' >> ~/.bashrc
source ~/.bashrc
02

CentOS / AlmaLinux / RHEL

bash
# Java 21
sudo dnf install java-21-openjdk-devel -y

# Java 17
sudo dnf install java-17-openjdk-devel -y

# Change version
sudo alternatives --config java
03

Windows Server

Method 1: Download from Adoptium (recommended)

Download from adoptium.net the .msi package for Windows x64.

Method 2: winget

powershell
# Java 21
winget install EclipseAdoptium.Temurin.21.JDK

# Java 17
winget install EclipseAdoptium.Temurin.17.JDK

# Java 11
winget install EclipseAdoptium.Temurin.11.JDK

Verify and set JAVA_HOME manually

powershell
# Verify installation
java -version

# Set JAVA_HOME (if not already set by installer)
[System.Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Eclipse Adoptium\jdk-21.0.0.37-hotspot", "Machine")
$env:PATH += ";$env:JAVA_HOME\bin"

# Verify
echo $env:JAVA_HOME
  • Choose Temurin 21 (LTS) or Temurin 17
  • Download the .msi file
  • Run the setup: it automatically includes JAVA_HOME and adds to PATH
04

Java for Minecraft/game servers

For Minecraft, PaperMC, etc.:

bash
# Install Java 21 (required by Minecraft 1.20.5+)
sudo apt install openjdk-21-jdk -y

# Run the server with optimized parameters for performance
java -Xms2G -Xmx4G \
  -XX:+UseG1GC \
  -XX:+ParallelRefProcEnabled \
  -XX:MaxGCPauseMillis=200 \
  -XX:+UnlockExperimentalVMOptions \
  -XX:+DisableExplicitGC \
  -XX:+AlwaysPreTouch \
  -XX:G1NewSizePercent=30 \
  -XX:G1MaxNewSizePercent=40 \
  -jar server.jar nogui

Where -Xms = minimum RAM and -Xmx = maximum RAM (adapt to your VPS).

05

Install a specific version (SDKMAN)

To manage multiple Java versions flexibly:

bash
# Install SDKMAN
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

# List available versions
sdk list java

# Install specific version
sdk install java 21.0.3-tem

# Change version in current project
sdk use java 17.0.11-tem

# Set global default
sdk default java 21.0.3-tem

DeluxHost, fondata nel 2023, offre soluzioni di hosting di alta qualità per diverse esigenze digitali. Forniamo hosting condiviso, VPS e server dedicati con sicurezza avanzata e datacenter globali.

© DeluxHost, Tutti i diritti riservati. | Partita IVA: IT17734661006
Tutti i sistemi operativi