How to Create a Minecraft Server in 5 Easy Steps

Posted on by Isaac Noboa | Updated:
Reading Time: 7 minutes

Minecraft is a sandbox/adventure game that challenges you to survive and explore an infinite world that you can modify at will. Just a few years after launching in 2009, Minecraft exploded in popularity, eventually becoming the highest-selling game of all time at 200 million copies.

A big reason for that is the freedom the game gives you in how you want to play (alone or with friends), whether it’s fighting, exploring, or building.

Leveraging Liquid Web's VPS hosting from our state-of-the-art data center offers a 100% network and power uptime guarantee as well as 24-hour server health monitoring.

All of our servers come with distributed denial of service (DDoS) attack protection plans, as we know that DDoS attacks are a concern to gamers and all of our customers. You get a secure server that will run your Minecraft install when you need it so that you can enjoy the many ways to play.

Learn how to create your own Minecraft server on CentOS 7 in 5 easy steps and manage your Minecraft server effortlessly with advanced server automation.

Setup Instructions

1. Install Java

The first step is to make sure that we have Java installed. Minecraft requires Java 1.8 or higher, so we must verify the installed version using java -version.

[user@host ~]$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

If Java is not installed, or you have an older version, we can fix that by using the sudo yum command.

[user@host ~]$ java -version
-bash: java: command not found
[user@host ~]$ sudo yum install java
[...]
Installed:
  java-1.8.0-openjdk.x86_64 1:1.8.0.292.b10-1.el7_9

2. Create a User

Next, we want to create a separate user with limited permissions for Minecraft. Creating a separate user with limited permissions is a security measure to prevent our VPS from being hacked even if the Minecraft server is compromised.

sudo useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft
  • -r creates the user as a system account instead of a regular user.
  • -m creates a home directory despite this being a system account.
  • -U creates a group that matches this user.
  • -d specifies the home directory for the user, in this case, /opt/minecraft.
  • -s specifies the shell, in this case, /bin/bash.

3. Minecraft Server Setup

We will switch to the Minecraft user and start setting up the server by downloading the official Java edition server inside a new folder called server.

[user@host ~]$ sudo su - minecraft
[sudo] password for user:
[minecraft@host ~]$ mkdir server
[minecraft@host ~]$ cd server
[minecraft@host server]$ wget https://launcher.mojang.com/[...]/server.jar
Note:
Make sure to replace the omitted link with the latest one provided on the official Java edition server page.

4. Start the Server & Agree to the EULA Terms

When we have the server downloaded, we can start it for the first time with the following command.

[minecraft@host server]$ java -Xmx1024M -Xms512M -jar server.jar nogui
[00:02:27] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

Now, we need to edit the eula.txt file to read and agree to the Mojang license terms. We can do that using the vim editor. With the file open:

  1. Press i to enter Insert mode.
  2. Change eula=true to eula=false.
  3. Press Escape to exit Insert mode.
  4. Type :wq to save your changes and exit the editor.
[minecraft@host server]$ vim eula.txt
#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Thu May 13 00:02:27 EDT 2021
eula=true

5. Ready to Play!

Now that the server is in place, we are ready to start playing. We will use the screen command to log out of the server while it still runs.

[minecraft@host server]$ screen

This will give us a new terminal window where we can then start the server.

[minecraft@host server]$ java -Xmx1024M -Xms1024M -jar /opt/minecraft/server/server.jar nogui

And we are done! The server will automatically generate a new random world, and when it’s done booting up, we can join the server by using the direct IP address or any domain name that we have on the VPS.

Can't Join The Server?

If you can’t join the server right away, don’t panic. Make sure you have port 25565 open in the firewall, which is the default Minecraft port.

While you still have this screen open, you can manage the server by typing commands directly and pressing Enter to make changes to players, items, and server settings, or to stop the server completely.

Finally, you can press Ctrl+A, then D to detach from this screen, which will place you back on the terminal window you were initially on while leaving Minecraft running inside the detached screen. Detaching the screen means you can now log out without stopping the process or use screen -r to reattach it and bring it back to the foreground.

Advanced Setup

We can perform some optional steps to make managing this Minecraft server much easier to use and enhance its abilities.

1. Set Up mcrcon

Rcon is a tool used to send commands to the game without logging in as a player. The Minecraft-specific client for rcon called mcrcon lets us create scripts to automate common server tasks, like starting, stopping, and changing the server settings using the built-in commands. These are the same commands we sent earlier on the screen, but using mcrcon allows us to automate the process.

It is possible to build mcrcon from source code in any Linux distribution, but since we’re on CentOS 7, we can simply install it using yum instead.

[user@host ~]$ sudo yum install mcrcon
[...]
Installed:
  mcrcon.x86_64 0:0.6.1-3.el7

Before we can use mcrcon to connect to our running server, we need to configure it by editing the server.properties file inside /opt/minecraft/server.

[minecraft@host ~]$ vim /opt/minecraft/server/server.properties

We will update the server and save the following values.

rcon.port=25575
rcon.password=example_password
enable-rcon=true
  • rcon.port can stay set to the default 25575. Because hackers could use this port to control your Minecraft server, don’t open the port to any IPs on your firewall that don’t require access.
  • rcon.password is a password you’ll need to use every time you want to connect to the rcon port. Remember to select a strong password, just as with any other website or service.
  • enable-rcon is false by default and must be changed to true.

2. Restart the Server

Now, we need to restart the server to make sure these changes go into effect. Since it is running inside the screen we created earlier, we will follow these steps to restart it.

1. Reattach the screen with screen -r to bring it back to the foreground.

2. Stop the server by typing the command stop and pressing Enter.

3. Start the server once again with the same command we used earlier.

[minecraft@host server]$ java -Xmx1024M -Xms1024M -jar /opt/minecraft/server/server.jar nogui

4. Detach from the screen by pressing Ctrl+A, then D.

3. Test the Server

With the server restarted and our changes applied, we can then test an mcrcon command.

[user@host ~]$ /usr/bin/mcrcon -H 127.0.0.1 -P 25575 -p 'example_password' 'say Hello world!'
  • -H is used to set the Minecraft host. We are using the localhost address since we implemented our command on the Minecraft server.
  • -P specifies the rcon port. If you have changed the default port 25575 on server.properties, make sure to change it here as well.
  • -p specifies the rcon password. Use the same secure password you set up on the previous step.

In this example, say Hello World! is the command we will send. Any players logged in to this Minecraft server will see a Hello World! message in their chat box if everything works. If that’s the case, we’re all set! You can now control your Minecraft server from the console without having to log in as a player. If you get a Connection refused error, double-check your port and password settings on the Minecraft server.

4. Set Up a Service for Minecraft

One of the most valuable things mcrcon allows is setting up Minecraft as a systemctl service managed automatically by the operating system.

Using our regular user instead of the Minecraft one, we will create a file named minecraft.service in the /etc/systemd/system/ directory.

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

Inside this file, we will paste the following text and save it using Ctrl+O like before.

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

[Service]
User=minecraft
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui
ExecStop=/usr/bin/mcrcon -H 127.0.0.1 -P 25575 -p example_password stop

[Install]
WantedBy=multi-user.target

Make sure to edit the rcon port (-P) and password (-p) in the ExecStop line to match your earlier configuration.

With that in place, we can load the service into the system with the following command.

[user@host ~]$ sudo systemctl daemon-reload 

This command doesn’t have any output, but once it’s complete, you can start, stop, and check the status of your Minecraft server with the following commands. If there is an issue, it will become apparent when running the sudo systemctl status minecraft command.

[user@host ~]$ sudo systemctl start minecraft
[user@host ~]$ sudo systemctl stop minecraft
[user@host ~]$ sudo systemctl status minecraft

Restarting the service like this is much easier than detaching and reattaching a screen, as we did earlier.

If you want the Minecraft service to start automatically after your server reboots, use the following command.

[user@host ~]$ sudo systemctl enable minecraft

5. Configure Minecraft Backups

Always configure Minecraft backups. Since saving multiple copies of the Minecraft world can take up a lot of space, we will use a Cloud Block Storage (CBS) drive mounted at /opt/minecraft/backups to store these backups.

We will use the vim text editor once again to create a new file.

[minecraft@host ~]$ vim /opt/minecraft/backup.sh

Paste the following code into the file.

#!/bin/bash

function rcon {
  /usr/bin/mcrcon -H 127.0.0.1 -P 25575 -p example_password "$1"
}

rcon "save-off"
rcon "save-all"
tar -cpzf /opt/minecraft/backups/world-$(date +%F-%H-%M).tar.gz /opt/minecraft/server
rcon "save-on"

find /opt/minecraft/backups/ -type f -mtime +7 -name '*.gz' -delete

This script will use rcon to save all world changes to the disk, compress them on a single tar file with today’s date, then delete any backups older than a week. To keep backups for a different number of days, replace the number in the -mtime +7 section with the desired number of days.

Once saved, we will register the backup as a cron job, so it’s executed once per day. To do so, edit your crontab.

[minecraft@host ~]$ crontab -e

Then, add the following line to run this backup script at 2:30 am.

30 2 * * * /opt/minecraft/tools/backup.sh

We’re done! Backups of the Minecraft world will now be saved once a day in our Cloud Block Storage drive and preserved for 7 days.

We’re Here to Help!

We hope you have enjoyed this tutorial about creating your own Minecraft server on a VPS running CentOS 7. If you’re ready to start hosting your own Minecraft server, check out our VPS server options today!

Gaming Banner

About the Author: Isaac Noboa

Budding software developer and general tinkerer. If there's one thing Isaac enjoys more than understanding how systems work, it's helping others do the same.

Have Some Questions?

Our Sales and Support teams are available 24 hours by phone or e-mail to assist.

1.800.580.4985
1.517.322.0434

Latest Articles

5 Alternatives to GitHub

Read Article

5 Steps to Install and Configure osquery on CentOS 7 & 8

Read Article

Five Steps to Create a Robots.txt File for Your Website

Read Article

Premium Business Email Pricing FAQ

Read Article

Microsoft Exchange Server Security Update

Read Article