Minecraft is a popular game that allows players to create and control their gaming worlds. Setting up a server enables you to customize the environment, manage player limits, and configure gameplay settings to suit your preferences. This guide covers setting up a Minecraft Java server on a Linux system.
The official wiki page recommends the following specs for running a Minecraft server.
For this guide, we’ll use a Hostman Ubuntu cloud machine configured with the following specifications: a dual-core 3 GHz CPU, 4 GB of RAM, 80 GB of NVMe storage, and a 200 Mbps bandwidth connection.
First, we’ll install tools like screen
to run the executable in the background, allowing us to continue using the terminal. We’ll also set up a non-root user to run the server securely. Additional security measures will be covered later.
Let’s proceed to the setup.
Let’s begin by updating the server and installing essential tools. Update the package list and upgrade existing packages:
sudo apt update && sudo apt upgrade -y
Next, we install essential tools like net-tools
and screen
:
sudo apt install net-tools screen -y
net-tools
, including netstat
, manages network connections, while screen
enables background Minecraft server operation.
Install the latest Java Development Kit to proceed:
sudo apt install openjdk-21-jdk
With these steps done, we can move to the setup.
First, add a new user called minecraft
(feel free to name whatever you want).
sudo useradd -r -U -d /usr/local/minecraft/server/ -s /sbin/nologin minecraft
The -s
option in the useradd
command specifies the login shell for the new user. By setting it to /sbin/nologin
, we effectively prevent the user from being able to log in interactively to the server. This will ensure that this user is only used to run the Minecraft server and reduce the attack surface.
Next, we create the directory structure to store the Minecraft server files:
sudo mkdir -p /usr/local/minecraft/server/Java
The -p
flag ensures that any missing parent directories are created automatically. This prepares a dedicated location to house all installation related files.
We assign ownership of the directory to the minecraft
user and group:
sudo chown -R minecraft: /usr/local/minecraft/server/
The -R
flag ensures permissions are applied recursively to all files and subdirectories. This allows the minecraft user to manage all server-related files without access issues.
We start by switching to the minecraft
user with an interactive shell to perform the setup tasks securely:
sudo su - minecraft -s /bin/bash
Next, we navigate to the server directory where all the Minecraft files will be stored:
cd /usr/local/minecraft/server/Java
Finally, we download the Minecraft server .jar
file from Mojang’s official servers:
wget https://piston-data.mojang.com/v1/objects/4707d00eb834b446575d89a61a11b5d548d8c001/server.jar
This ensures the Minecraft executable is in the correct location and ready for further configuration. We recommend updating the URL if a newer server file version is available.
We start the Minecraft server using the following command:
java -Xmx1024M -Xms1024M -jar server.jar nogui
This command allocates 1GB of memory to the server (-Xmx
for the maximum and -Xms
for the initial allocation). The nogui
option disables the graphical interface, making it more efficient for a server environment by reducing resource usage.
You might first encounter an error due to the EULA similar to this:
When the server is started for the first time, it exits with a message requiring acceptance of the Minecraft End-user License Agreement (EULA). During this process, several files are created in the server directory:
ls
eula.txt libraries logs server.jar server.properties
To accept the EULA, we update the eula.txt
file by replacing false
with TRUE
using the following command:
sed -i 's/\bfalse\b/TRUE/' eula.txt
This command edits the file, eliminating the need to open an editor like Vim or Nano.
With the EULA accepted, the server can now be launched. Use the screen
command to run the server in the background:
screen -S mc_Java_server -dm java -Xmx1024M -Xms1024M -jar server.jar nogui
Create a session named mc_Java_server
, which allows detaching from the terminal while keeping the server active.
Great! The Minecraft service is now running and accessible at your IP address on port 25565.
To connect in multiplayer mode, open Minecraft and add a new address.
Once done, you can join the server after your client has established a connection.
Use online tools like mcsrvstat.us to check if the server is online. It also displays details such as player count, Minecraft version, and debug information.
Now that the Minecraft server is set up, let’s improve security and resource management.
With the Minecraft server set up, focusing on securing the server and optimizing resource management is essential. Implementing these tips will help ensure smooth performance while protecting against potential vulnerabilities.
Set up a firewall to control traffic and block unauthorized access:
Allow only necessary ports, such as 25565 for Minecraft, using tools like ufw
or iptables
:
sudo ufw allow ssh
sudo ufw allow 25565
sudo ufw enable
Block all other incoming traffic unless explicitly required for different services.
A firewall protects the server from external threats by ensuring that only expected traffic can reach it.
Activate the server whitelist to restrict access to specific players:
# In the Minecraft console or server.properties file:
whitelist=true
Add trusted players to the whitelist:
whitelist add <player_username>
This ensures that only approved players can access your machine, reducing the risk of griefing or malicious activities.
Always run the Minecraft server under a non-root user account, like the minecraft
user we created earlier. This limits the machine’s permissions, ensuring it cannot harm the underlying system even if the server is compromised.
Optimize memory usage to match the server’s workload. Allocate a specific amount of RAM to the server using the -Xmx
and -Xms
flags in the Java command.
For example, allocate 2GB of RAM:
java -Xmx2048M -Xms2048M -jar server.jar nogui
You can monitor RAM usage using tools like htop
to ensure the server runs smoothly without exhausting system resources.
You can restrict the maximum number of players in server.properties to match your server’s capacity:
max-players=10
Plugins are a great way to expand your Minecraft server's functionality with features like anti-griefing tools, economy systems, or mini-games. Here are some recommended plugins:
Refer to our tutorial for plugin installation, from downloading to placing them in the correct directory. These enhancements will improve security and user experience.
This article covered the steps to install a Minecraft gaming server on a remote Ubuntu machine and best practices for maintenance and providing a fantastic player experience.
Consider our ready-to-run Minecraft servers available at Hostman Marketplace for a hassle-free setup.