Java is a versatile programming language widely used for building web applications, backend systems, and mobile apps. Installing Java on your VPS is essential if you’re looking to deploy Java-based applications on AnonVM. This guide will walk you through installing Java Development Kit (JDK) and setting up Java on your AnonVM VPS.
System Requirements
Before you begin, ensure that your VPS meets the following requirements:
- OS: Ubuntu 18.04+, Debian, or CentOS 7+
- RAM: Minimum of 1GB recommended
- Access: Root or sudo user privileges
Step 1: Update Your System
To avoid any compatibility issues, start by updating your system’s package manager.
For Ubuntu/Debian:
For CentOS:
Step 2: Choose the Right Java Version
Java comes in several versions, including:
- Java SE 8 - Widely supported and used for many applications.
- Java SE 11 (LTS) - Long-term support release.
- Java SE 17 (LTS) - Latest LTS version, highly recommended.
Most software supports Java 8 or later, but Java 17 is recommended for long-term projects.
Step 3: Install Java on Ubuntu/Debian
Option 1: Install OpenJDK from Default Repositories
To install the OpenJDK version 11 (for example):
To install Java 17:
Option 2: Install Oracle JDK
For Oracle JDK, you need to download the binaries manually. Visit Oracle's Java Downloads page and follow the instructions for installation.
Step 4: Install Java on CentOS
-
Enable OpenJDK repository (Java 11):
-
Verify the installation:
-
Alternative - Install Oracle JDK on CentOS
Download the RPM file from Oracle's website and install it manually.
Step 5: Set Java Environment Variables
After installing Java, you should configure environment variables such as JAVA_HOME
and PATH
to make it easier to run Java commands globally.
-
Locate Java Installation Path:
Use the following command to find the path to the installed Java version:
The output will show the installation path (e.g.,
/usr/lib/jvm/java-11-openjdk-amd64
). -
Set JAVA_HOME and PATH Variables:
Add the following lines to your
.bashrc
file:Replace the path
/usr/lib/jvm/java-11-openjdk-amd64
with the path from the previous step. -
Verify Environment Variables:
Both should show the correct paths, confirming that the environment variables are correctly set.
Step 6: Testing Your Java Installation
To verify your Java installation, create a simple Java program and compile it.
-
Create a Test Java File:
Paste the following code:
-
Compile the Program:
-
Run the Program:
If everything is installed correctly, you should see:
Step 7: Install Maven or Gradle (Optional)
Maven and Gradle are popular build automation tools for Java. They manage dependencies and streamline building, testing, and deploying applications.
Installing Maven
-
Install Maven on Ubuntu:
-
Install Maven on CentOS:
-
Verify Maven Installation:
Installing Gradle
-
Download Gradle:
-
Extract Gradle:
-
Add Gradle to PATH:
-
Verify Gradle Installation:
Step 8: Deploy a Sample Java Application (Optional)
To confirm that your environment is fully set up, try deploying a Java application, either manually or using Maven/Gradle.
Using Maven
-
Create a Maven Project:
-
Compile the Project:
-
Run the Application:
You should see the output of your sample Maven application.
Conclusion
Java is now installed and configured on your VPS with AnonVM. You have set up Java, verified the installation, and optionally configured Maven or Gradle for building Java applications. You’re ready to develop, test, and deploy Java applications on your server! For more advanced projects, consider setting up a CI/CD pipeline to automate builds and deployments.