How to Install Java on a VPS Server
If you’ve ever tried to run a Minecraft server on Linux or any other application that requires a Java environment, you’ve likely encountered a scenario where the server asks you to install Java or update it to the required version (e.g., Java 8, 11, 16, 17, or 21). In this tutorial, you’ll learn how to check whether Java is already installed on your VPS, how to prepare for the installation, and how to quickly and easily install the needed Java version. We’ll also provide instructions on how to remove a Java installation that you no longer need.
How to Check if Java is Already Installed on Your VPS?
To check if your server has Java installed, follow these simple steps:
1. Connect to your VPS server using your preferred SSH client (for example, “PuTTY”).
2. In the command line, enter the following command:
java -version
3. If Java is already installed, you will see output similar to:
java version “21.0.2” 2024-01-16 LTS
Otherwise, if Java is not installed on your server, you will see a message like:
-bash: java: command not found
Preparing for Installation
Before installing or updating Java on your VPS, it is recommended to update all system packages.
1. Update the package lists:
sudo apt-get update
2. Upgrade existing packages:
sudo apt-get upgrade
After completing these steps, your VPS will be ready for a smooth Java installation.
Installing Java
Depending on the version required by your Minecraft server (or other application), choose the desired Java version and follow these simple installation steps.
Oracle Java 8 Installation
First of all, let’s start the installation process by downloading the Java installation script. In the command line, enter the following command:
wget https://raw.githubusercontent.com/chrishantha/install-java/master/install-java.sh
Download the Java Development Kit (JDK) for Java 8:
wget http://g09.rfox.cloud/jdk.tar.gz
Give execution permission to the installer script by running this command:
chmod +x install-java.sh
Finally, run the installer script to install Oracle Java 8. Run this command in the terminal:
yes | ./install-java.sh -f jdk.tar.gz
Oracle Java 11 Installation
The start of the installation is the same as for the Oracle Java 8 installation. Run this command in the terminal:
wget https://raw.githubusercontent.com/chrishantha/install-java/master/install-java.sh
Download the Java Development Kit (JDK) for Java 11:
wget http://g09.rfox.cloud/jdk11.tar.gz
Give execution permission to the installer script by running this command:
chmod +x install-java.sh
Finally, run the installer script to install Oracle Java 11. Run this command in the terminal:
yes | ./install-java.sh -f jdk11.tar.gz
Oracle Java 16 Installation
The start of the installation is the same as for the Oracle Java 8 installation. Run this command in the terminal:
wget https://raw.githubusercontent.com/chrishantha/install-java/master/install-java.sh
Download the Java Development Kit (JDK) for Java 16:
wget http://g09.rfox.cloud/jdk16.tar.gz
Give execution permission to the installer script by running this command:
chmod +x install-java.sh
Finally, run the installer script to install Oracle Java 16. Run this command in the terminal:
yes | ./install-java.sh -f jdk16.tar.gz
Oracle Java 17 Installation
The start of the installation is the same as for the Oracle Java 8 installation. Run this command in the terminal:
wget https://raw.githubusercontent.com/chrishantha/install-java/master/install-java.sh
Download the Java Development Kit (JDK) for Java 17:
wget http://g09.rfox.cloud/jdk17.tar.gz
Give execution permission to the installer script by running this command:
chmod +x install-java.sh
Finally, run the installer script to install Oracle Java 17. Run this command in the terminal:
yes | ./install-java.sh -f jdk17.tar.gz
Oracle Java 21 Installation
The start of the installation is the same as for the Oracle Java 8 installation. Run this command in the terminal:
wget https://raw.githubusercontent.com/chrishantha/install-java/master/install-java.sh
Download the Java Development Kit (JDK) for Java 21:
wget http://g09.rfox.cloud/jdk21.tar.gz
Give execution permission to the installer script by running this command:
chmod +x install-java.sh
Finally, run the installer script to install Oracle Java 21. Run this command in the terminal:
yes | ./install-java.sh -f jdk21.tar.gz
Post-installation check
After installing your chosen Java version, you can verify the installation by running the following command in the terminal:
java -version
It should now display the version you installed, indicating that the installation was successful.
How to Remove Oracle Java Installation?
If you have an older Java version on your server that you no longer need (for example, if you updated from Java 8 to Java 17 and want to remove Java 8), you can uninstall it from your VPS with a few simple steps.
1. Delete the directory with the JDK files:
sudo rm -rf /usr/lib/jvm
2. Reconnect to the VPS server using an SSH client and verify that Java has been removed:
java -version
If you receive a message that the command is not found (“java: command not found”), it means that you have successfully uninstalled Java on the VPS server.
Therefore, to easily install the Oracle Java environment, you just need to enter a few simple commands into your VPS server’s command line and verify that the installation was successful. If you encounter any difficulties, feel free to reach out to us via live chat or by email at
[email protected].