Skip to Content

How to Create a Minecraft Server on Ubuntu 20.04

In this tutorial, you'll learn how to set up your very own dedicated Minecraft server in a Linux Ubuntu 20.04 environment, giving you full control of storage, memory, processing power, and everything else behind the scenes. Let's get started!

The Benefits of Creating Your Own Minecraft Server

With a dedicated Minecraft server on Ubuntu, you're in control of everything from storage and memory to processing power and bandwidth. Here is a rundown of the benefits:

  • Full control of installed plugins and mods
  • Dedicated resources for storage, memory, and bandwidth resources
  • Improved performance overall
  • Increased privacy

Minecraft Server Prerequisites

To run Minecraft smoothly, make sure to set up a Ubuntu server with the following minimum requirements:

  • 4GB RAM
  • 80GB disk space
  • Intel core-based CPU
  • Command Line access

Choosing a Service Provider

There are many service providers to choose from. It really just depends on who you're comfortable with. You may already have a service provider that offers access to Cloud-based or dedicated Linux servers. If this is the case, see what they have to offer.

My provider of choice is Lightsail through Amazon Web Services (AWS). You can set up an instance with a dedicated IP address in just a few minutes. It's extremely reliable, and it's easy to use and navigate. And you have full control over your instances that you set up, which is a plus.

At the time of this writing, a Ubuntu 20.04 Lightsail instance through AWS with the minimum server requirements costs $20 per month. This gives you the 4GB RAM and 80GB hard drive space you need, plus 4TB of data transfer. There is an additional fee for extra bandwidth used, but you'll likely not reach it unless you're playing with tons of people.

Install the Required Packages

Assuming you have an environment set up or are just curious about what comes next, let's continue! Let's make sure all Ubuntu packages are up-to-date by running the following two commands:

$ sudo apt update
$ sudo apt install git build-essential

Install the Java Runtime Environment

Java 8 or above is required for Minecraft to run. This step uses the latest headless JRE because Minecraft isn't compatible with a graphical user interface:

$ sudo apt install openjdk-17-jre-headless

Once finished, you can verify the Java installation by entering the following command:

$ java -version

This command should show you the latest version of the Java JDK installed on the server. If you see something else, or an error message, something went wrong with the installation and you'll need to run through the process again.

Create the Minecraft User

This step is necessary for security purposes as you don't want to run the game under the root user. Doing so could open up the server to vulnerabilities.

The following command will create a new user named minecraft paired to the /opt/minecraft directory:

$ sudo useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft

The next thing we'll need to do for our user is set the new minecraft directory permissions so the new user can access the files and directory structure when executed as a service:

$ cd /opt
$ sudo chmod -R 777 minecraft
$ cd /opt/minecraft

Download and Configure the Minecraft Server

Make sure you're still in the /opt/minecraft directory and run the following command to download the latest vanilla Minecraft JAR file from Mojang's public server:

$ wget https://launcher.mojang.com/v1/objects/c8f83c5655308435b3dcf03c06d9fe8740a77469/server.jar
You'll need to make sure you're downloading the JAR file that matches your Minecraft Java Edition version. At the time of this writing, version 1.18.2 was downloaded from the above location. You can always check for the latest Minecraft JAR file here if you're running a different version.

Now, we'll attempt to start run the downloaded JAR file, but it will fail:

$ java -Xmx1024M -Xms512M -jar server.jar nogui

This command will create two configuration files that we'll need to go in and edit, eula.txt and server.properties.

We'll need to agree to the End-User License Agreement by editing the eula.txt file first:

$ nano eula.txt

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

Then, we can optionally open the server.properties file and edit some of the settings here. Here's a quick run-down of some of the more popular settings that you're probably already familiar with:

  • difficulty: Sets the difficulty of the game, including amount of damage dealt, how elements affect players, etc. The available options are peaceful, easy, normal, and hard.
  • gamemode: Sets the gameplay mode. The available options are survival, creative, adventure, and spectator.
  • level-name: Sets the name of your server that will appear in the client window. Some characters are limited and can be escaped using a backslash.
  • motd: Enables Player versus Player combat mode. If set to true, players will be able to engage in combat against each other in-game.

Running Minecraft as a Service

Running Minecraft as a service allows it to run in the background, so we don't need to be logged in and run the Minecraft server manually. To accomplish this, we'll need to create a new Systemd unit file in the /etc/systemd/system directory, and edit the file:

$ cd /etc/systemd/system
$ sudo touch minecraft.service
$ nano minecraft.service

And paste the following configuration into the file and save:

[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
ExecStart=java -Xmx1024M -Xms512M -jar server.jar nogui

[Install]
WantedBy=multi-user.target

Make sure to modify the Xms and Xmx flags according to the Ubuntu server's specifications. The Xms flag defines the initial memory allocation while the Xmx flag defines the maximum memory allocation for a Java Virtual Machine (JVM).

Start the Minecraft Server

We can now start our newly created Minecraft server:

$ sudo systemctl start minecraft

Check the Minecraft server status:

$ sudo systemctl status minecraft

And enable the Minecraft service at boot time:

$ sudo systemctl enable minecraft

Enable the Port in the Firewall

We need to ensure that our Minecraft server can be accessed from outside the server's local network by opening port 25565:

$ sudo ufw allow 25565/tcp

Connect to the Minecraft Server from the Java Edition

Make note of the server's public IP address, as we'll need this to connect to our new Minecraft server.

Open Minecraft Java Edition, click the Multiplayer button, then click the Direct Connection button, where we'll enter the public IP address and the port number selected in our configuration:

[public-ip-address]:25565

Conclusion

That's it! At this point, you should have a successful and running Minecraft server configuration and should be able to connect to it from the Minecraft Java Edition.

This configuration took a bit of trial and error to get set up correctly. If you run into any issues, let me know in the comments below and I'll hop on to help!

Last Updated: May 08, 2022
Created: March 30, 2022

Comments

Teddy

2y
For some reason, I had to reset the folder permissions again after running the full installation to get Minecraft to run as a service:

chmod -R 777 minecraft

But, once I did that, it worked great! Thanks for this!

Reply

Add A Comment

Comment Etiquette: Wrap code in a <code> and </code>. Please keep comments on-topic, do not post spam, keep the conversation constructive, and be nice to each other.