Scroll to top
how to install minecraft server
Comprehensive Guide to Installing Minecraft Server on Ubuntu 22.04 VPS

How to Install a Minecraft Server on Ubuntu 22.04 VPS

Step-by-Step Instructions for a Smooth Minecraft Server Setup

How to Install a Minecraft Server on Ubuntu 22.04 VPS

This guide will walk you through the process of setting up a Minecraft server on an Ubuntu 22.04 VPS. It includes every command you'll need, with detailed instructions for each step.

Prerequisites

  • A VPS running Ubuntu 22.04
  • A user with sudo privileges
  • Basic knowledge of terminal commands

Step 1: Update and Upgrade Your System

First, ensure your system is up-to-date:

																								sudo apt update && sudo apt upgrade -y
																							

Step 2: Install Java

Minecraft requires Java to run. Install OpenJDK 17, which is the recommended version for Minecraft servers:

																								sudo apt install openjdk-17-jre-headless -y
																							

Verify the installation:

																								java -version
																							

You should see output similar to `openjdk version "17.0.x"`.

Step 3: Create a Directory for Minecraft Server

Create a directory where your Minecraft server files will be stored:

																								mkdir ~/minecraft
cd ~/minecraft
																							

Step 4: Download Minecraft Server

Download the latest version of the Minecraft server from the official website:

																								wget https://launcher.mojang.com/v1/objects/e3b2d9e4d27b20a83e1ab2cc36a521b9940c0ad8/server.jar -O server.jar
																							

Step 5: Run the Minecraft Server

Start the Minecraft server to generate the necessary configuration files:

																								java -Xmx1024M -Xms1024M -jar server.jar nogui
																							

The server will start and then stop, prompting you to accept the EULA.

Step 6: Accept the EULA

To run the Minecraft server, you need to accept the End User License Agreement (EULA). Follow these steps to accept the EULA:

  1. Open the EULA file using a text editor such as nano:
  2. 																									nano eula.txt
    																								
  3. In the nano editor, you will see the following line:
  4. 																									eula=false
    																								
  5. Change this line to:
  6. 																									eula=true
    																								
  7. To save and close the file in nano:
    • Press CTRL + X to begin the process of exiting nano.
    • Nano will ask if you want to save the modified buffer. Press Y to confirm that you want to save the changes.
    • Nano will then ask for the file name to write. Press Enter to confirm the current file name.

    After performing these steps, the changes will be saved, and you will have accepted the EULA. Now, you can proceed to start the Minecraft server.

Step 7: Configure the Minecraft Server

Edit the server.properties file to customize your Minecraft server settings:

																								nano server.properties
																							

Adjust the settings according to your preferences. Common settings to change include:

  • motd: The message of the day displayed in the server list.
  • max-players: Maximum number of players that can join.
  • spawn-protection: Radius of spawn protection.
  • online-mode: Set to true to enable player authentication through Mojang's servers.

After making your changes, save and close the file.

Step 8: Start the Minecraft Server

Now that you have accepted the EULA, you can start your Minecraft server. Additionally, you can adjust the amount of RAM allocated to the server based on your VPS's available resources. Follow these steps:

Setting the Amount of RAM

The -Xmx and -Xms flags are used to specify the maximum and initial heap size for the Java Virtual Machine (JVM). Here's what they mean:

  • -Xmx: Sets the maximum heap size. This is the maximum amount of RAM that the server will use.
  • -Xms: Sets the initial heap size. This is the amount of RAM that the server will use on startup.

For example, to allocate 2GB of RAM to the server, you would use:

																								java -Xmx2048M -Xms2048M -jar server.jar nogui
																							

To allocate 4GB of RAM, you would use:

																								java -Xmx4096M -Xms4096M -jar server.jar nogui
																							

Adjust the values based on your VPS's available RAM and the needs of your server.

Running the Server

Run the server with the desired amount of RAM:

																								java -Xmx1024M -Xms1024M -jar server.jar nogui
																							

Using screen

To keep the server running even after you log out, you can use screen or tmux. Here, we'll use screen:

Install screen if it’s not already installed:

																								sudo apt install screen -y
																							

Start a new screen session and run the server:

																								screen -S minecraft
java -Xmx1024M -Xms1024M -jar server.jar nogui
																							

To detach from the screen session, press Ctrl + A, then D.

To reattach to the screen session, use:

																								screen -r minecraft
																							

Step 9: Allow Minecraft Port in Firewall

Allow the default Minecraft port (25565) through the firewall:

																								sudo ufw allow 25565
																							

Ensure the firewall is enabled:

																								sudo ufw enable
																							

Step 10: Managing Your Minecraft Server

To stop the server, enter the server console and type:

																								stop
																							

To automate server startup, you can create a systemd service.

Step 11: Create a Systemd Service

Create a new service file for the Minecraft server:

																								sudo nano /etc/systemd/system/minecraft.service
																							

Add the following content to the file:

																								[Unit]
Description=Minecraft Server
After=network.target

[Service]
User=your-username
WorkingDirectory=/home/your-username/minecraft
ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui
Restart=on-failure

[Install]
WantedBy=multi-user.target
																							

Replace your-username with your actual username.

Save and close the file, then reload the systemd daemon:

																								sudo systemctl daemon-reload
																							

Start the Minecraft server with systemd:

																								sudo systemctl start minecraft
																							

Enable the Minecraft server to start on boot:

																								sudo systemctl enable minecraft
																							

Step 12: Monitor the Server

Check the status of your Minecraft server:

																								sudo systemctl status minecraft
																							

Step 13: Backing Up Your Server

Regular backups are essential. You can create a simple backup script:

Create a backup directory:

																								mkdir ~/minecraft/backups
																							

Create a backup script:

																								nano ~/minecraft/backup.sh
																							

Add the following content:

																								#!/bin/bash
tar -cvpzf ~/minecraft/backups/minecraft_backup_$(date +%Y%m%d_%H%M%S).tar.gz ~/minecraft
																							

Make the script executable:

																								chmod +x ~/minecraft/backup.sh
																							

You can automate the backup process using cron:

																								crontab -e
																							

Add the following line to schedule a daily backup at 2 AM:

																								0 2 * * * /home/your-username/minecraft/backup.sh
																							

Replace your-username with your actual username.

Conclusion

By following these steps, you will have a fully functional Minecraft server running on your Ubuntu 22.04 VPS. This setup ensures a stable, secure, and high-performance environment for you and your friends to enjoy Minecraft.

Minecraft Server Setup FAQ Section

What is a Minecraft server?

A Minecraft server allows players to connect to a central computer that hosts the game world. This enables multiple players to join and play in the same world, interacting with each other in real-time.

What are the system requirements for a Minecraft server?

The system requirements vary based on the number of players and the desired performance. For a small server (up to 10 players), you should have at least 1GB of RAM, a multi-core CPU, and a stable internet connection. For larger servers, increase RAM and CPU power accordingly.

How do I allocate more RAM to my Minecraft server?

To allocate more RAM, adjust the -Xmx (maximum) and -Xms (initial) flags in the server start command. For example, to allocate 2GB of RAM, use:

																								java -Xmx2048M -Xms2048M -jar server.jar nogui
																							
How can I keep my Minecraft server running after I log out?

To keep the server running, use a tool like screen or tmux. For screen, you can start a session with:

																								screen -S minecraft
																							

Then start the server:

																								java -Xmx1024M -Xms1024M -jar server.jar nogui
																							

Detach from the screen session with Ctrl + A, then D. Reattach with:

																								screen -r minecraft
																							
How do I update my Minecraft server?

To update your Minecraft server, download the latest server version from the official website, replace the existing server.jar file, and restart the server. Ensure you backup your server files before updating.

How do I create a backup of my Minecraft server?

Create a backup by archiving your server files. Use the following script to automate the process:

																								#!/bin/bash
tar -cvpzf ~/minecraft/backups/minecraft_backup_$(date +%Y%m%d_%H%M%S).tar.gz ~/minecraft
																							

Make the script executable and schedule it with cron for regular backups.

How do I secure my Minecraft server?

Secure your server by enabling a firewall, allowing only necessary ports (e.g., 25565 for Minecraft), keeping your server software updated, and setting up automated backups. Regularly monitor server activity for any suspicious behavior.

What are the best practices for optimizing Minecraft server performance?

Optimize performance by allocating sufficient RAM, using performance-enhancing plugins like Paper or Spigot, regularly monitoring server resources, and optimizing server configuration settings. Additionally, consider using SSD storage for faster read/write speeds.

Can I run multiple Minecraft servers on a single VPS?

Yes, you can run multiple Minecraft servers on a single VPS by setting up separate directories for each server and configuring them to use different ports. Ensure your VPS has enough resources (CPU, RAM, storage) to handle multiple instances.

How do I install plugins on my Minecraft server?

To install plugins, first, download the desired plugin from a trusted source (e.g., SpigotMC or Bukkit). Place the plugin's .jar file in the plugins directory of your Minecraft server, then restart the server to load the new plugin.

Can't find an answer? Contact our customer support now!