UbuntuUbuntu Based

How To Install Minecraft Server on Ubuntu 24.04 LTS

Install Minecraft Server on Ubuntu 24.04

Minecraft, the beloved sandbox game that has captured the hearts of millions worldwide, offers endless possibilities for creativity and adventure. While playing solo or on public servers can be fun, hosting your own Minecraft server opens up a whole new realm of experiences. It allows you to create a personalized gaming environment, set your own rules, and play with a select group of friends or family members.

Ubuntu 24.04 LTS, the latest long-term support release of the popular Linux distribution, provides an excellent platform for hosting a Minecraft server. Its stability, security features, and robust performance make it an ideal choice for gamers and server administrators alike. In this comprehensive guide, we’ll walk you through the process of installing and configuring a Minecraft server on Ubuntu 24.04 LTS, ensuring you have all the tools and knowledge needed to create your very own Minecraft world.

Prerequisites

Before we dive into the installation process, let’s ensure you have everything needed to set up your Minecraft server successfully:

  • Hardware Requirements: A computer or virtual private server (VPS) with at least 4GB of RAM, a dual-core processor, and 20GB of free disk space. For optimal performance, especially with multiple players, consider using 8GB of RAM or more.
  • Software Requirements: Ubuntu 24.04 LTS installed and updated. You’ll also need SSH access if you’re setting this up on a remote server.
  • Internet Connection: A stable and reasonably fast internet connection, preferably with a static IP address or dynamic DNS set up.
  • Basic Linux Knowledge: Familiarity with basic Linux commands and text editors like nano or vim will be helpful.

Ensure you have root or sudo access on your Ubuntu system, as we’ll be performing operations that require administrative privileges.

Updating Ubuntu and Installing Dependencies

The first step in setting up your Minecraft server is to ensure your Ubuntu system is up-to-date and has all the necessary dependencies installed. Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade -y
sudo apt install openjdk-17-jre-headless screen -y

These commands will update your system’s package list, upgrade all installed packages to their latest versions, and install the Java Runtime Environment (JRE) along with the screen utility. Java is essential for running the Minecraft server, while screen allows you to run the server in the background.

After the installation is complete, verify that Java is correctly installed by running:

java -version

You should see output indicating the installed Java version.

Creating a Dedicated Minecraft User

For security reasons, it’s best to run the Minecraft server under a dedicated user account rather than using the root user. This practice helps isolate the server process and limits potential security risks. To create a new user for Minecraft, execute the following command:

sudo adduser minecraft

Follow the prompts to set a password and provide any additional information for the new user. Once created, switch to the new user account:

su - minecraft

Downloading Minecraft Server Files

Now that we have our dedicated user set up, let’s download the Minecraft server files. First, create a directory for the server:

mkdir ~/minecraft_server
cd ~/minecraft_server

Next, download the latest version of the Minecraft server JAR file. You can find the most recent version on the official Minecraft website. At the time of writing, the latest version is 1.20.4, but be sure to check for the most current release. Use wget to download the file:

wget https://piston-data.mojang.com/v1/objects/8dd1a28015f51b1803213892b50b7b4fc76e594d/server.jar

After downloading, verify the file’s integrity by checking its size and comparing it to the official download page.

Configuring the Minecraft Server

With the server file downloaded, we can now begin the configuration process. Start by running the server once to generate the necessary configuration files:

java -Xmx1024M -Xms1024M -jar server.jar nogui

This command will start the server with 1GB of RAM allocated. The server will generate several files and folders before stopping due to the EULA not being accepted. To accept the EULA, open the eula.txt file:

nano eula.txt

Change the line eula=false to eula=true, save the file, and exit the editor.

Next, let’s configure the server properties. Open the server.properties file:

nano server.properties

Here, you can customize various settings such as the server name, game mode, difficulty, and maximum number of players. Some important settings to consider include:

  • server-port=25565 (default Minecraft port)
  • gamemode=survival (or creative, adventure, spectator)
  • difficulty=normal (easy, normal, hard, peaceful)
  • max-players=20 (adjust based on your server’s capacity)
  • white-list=true (if you want to restrict access to specific players)

Save your changes and exit the editor.

Setting Up Firewall Rules

To allow players to connect to your Minecraft server, you need to configure your firewall to allow incoming connections on the Minecraft port (default is 25565). If you’re using Ubuntu’s default firewall, UFW, you can set this up with the following commands:

sudo ufw allow 25565/tcp
sudo ufw enable

If you’re running the server on a cloud platform or have a router between your server and the internet, make sure to configure any additional firewalls or security groups to allow traffic on port 25565.

Creating a Startup Script

To make starting and stopping the Minecraft server easier, let’s create a simple bash script. Create a new file called start_minecraft.sh in the minecraft_server directory:

nano ~/minecraft_server/start_minecraft.sh

Add the following content to the file:

#!/bin/bash
cd ~/minecraft_server
java -Xmx2048M -Xms1024M -jar server.jar nogui

Save the file and make it executable:

chmod +x ~/minecraft_server/start_minecraft.sh

Now you can start your Minecraft server by running ./start_minecraft.sh from the minecraft_server directory.

Setting Up a Systemd Service

To ensure your Minecraft server starts automatically when your Ubuntu system boots up, we’ll create a systemd service. Create a new service file:

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

Add the following content to the file:

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

[Service]
User=minecraft
WorkingDirectory=/home/minecraft/minecraft_server
ExecStart=/home/minecraft/minecraft_server/start_minecraft.sh
Restart=always

[Install]
WantedBy=multi-user.target

Save the file and exit the editor. Now, reload the systemd manager to recognize the new service:

sudo systemctl daemon-reload

Enable the service to start on boot and start it immediately:

sudo systemctl enable minecraft
sudo systemctl start minecraft

You can check the status of your Minecraft server at any time using:

sudo systemctl status minecraft

Optimizing Server Performance

To ensure your Minecraft server runs smoothly, consider the following optimizations:

  1. Adjust Java Heap Size: Modify the -Xmx and -Xms values in your startup script based on your server’s available RAM. For example, for a server with 8GB of RAM, you might use -Xmx6G -Xms4G.
  2. Use Aikar’s Flags: These are optimized JVM arguments for Minecraft servers. Add them to your startup script for better performance.
  3. Reduce View Distance: In server.properties, lower the view-distance value to reduce server load.
  4. Optimize World Settings: Use tools like PaperMC or Spigot for more advanced server optimization options.

Backing Up Your Minecraft Server

Regular backups are crucial to protect your Minecraft world and player data. Create a simple backup script:

nano ~/minecraft_server/backup.sh

Add the following content:

#!/bin/bash
BACKUP_DIR="/home/minecraft/backups"
MINECRAFT_DIR="/home/minecraft/minecraft_server"
DATE=$(date +%Y-%m-%d_%H-%M-%S)

mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_DIR/minecraft_backup_$DATE.tar.gz" -C "$MINECRAFT_DIR" .

find "$BACKUP_DIR" -type f -mtime +7 -delete

Make the script executable and set up a cron job to run it daily:

chmod +x ~/minecraft_server/backup.sh
crontab -e

Add the following line to run the backup daily at 3 AM:

0 3 * * * /home/minecraft/minecraft_server/backup.sh

Troubleshooting Common Issues

If you encounter problems with your Minecraft server, try these troubleshooting steps:

  • Connection Issues: Verify firewall settings and ensure the correct port is open.
  • Java Errors: Check Java version compatibility with your Minecraft server version.
  • Performance Problems: Monitor server resources and adjust Java heap size or server settings accordingly.
  • World Corruption: Restore from a recent backup and ensure proper server shutdown procedures are followed.

Updating the Minecraft Server

To update your Minecraft server to the latest version:

  1. Stop the server: sudo systemctl stop minecraft
  2. Backup your current server files
  3. Download the new server.jar file
  4. Replace the old server.jar with the new one
  5. Start the server: sudo systemctl start minecraft

Congratulations! You have successfully installed Minecraft. Thanks for using this tutorial for installing the Minecraft server on your Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Minecraft website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button