PicoBlog

How to Run a Minecraft Server on Ubuntu 22.04

UPDATED 6/24/2024: New Java version and server jar URL.

TUTORIAL WARNING: This article is a tutorial. If you like tutorials, cool. If you do not like tutorials, move along.

Embark on an exciting journey with me as I take you through the process of setting up your very own Minecraft server using Ubuntu 22.04.

In this hands-on tutorial, I'll run through how to get a Vanilla Minecraft server up and running on Ubuntu 22.04. This makes for an excellent project, whether you're an avid Minecraft fan or are looking to dive into the world of self hosting.

Before we dive in, you will need:

  • a server - For my example, I am using a Proxmox VM with 4 CPU cores, 16GB RAM and 50GB SSD storage, however, if you're the only player, you might be able to manage with less.

  • a basic familiarity with Ubuntu

  • a public IP address not obscured behind a NAT

Great. Let’s get started.

Here I am using Proxmox. You can create this Ubuntu VM in your own homelab or on a cloud somewhere out there.

Now that we created a VM, let’s SSH in:

ssh <username>@<ip address>

Let’s first update and upgrade all packages:

sudo apt update && sudo apt upgrade -y && sudo apt -y autoremove && sudo apt -y autoclean

Let’s reboot for good measure:

sudo reboot

Once the machine comes back up, we can SSH back in and run the following to install dependencies and pre-req packages:

sudo apt install software-properties-common screen -y && sudo apt install openjdk-21-jdk -y

Accept the Java JDK EULA and finish out the install.

After this finishes, we can create a script:

sudo touch setup.sh && sudo chmod u+x setup.sh

Let’s edit the file:

sudo nano setup.sh

Paste the following:

#!/bin/bash # Create the Minecraft server directory sudo mkdir /opt/minecraft # Download the Minecraft server jar file (at time of writing 1.20.4) wget https://piston-data.mojang.com/v1/objects/450698d1863ab5180c25d7c804ef0fe6369dd1ba/server.jar # Move the jar file sudo mv server.jar /opt/minecraft cd /opt/minecraft # Run the server once to generate eula.txt file, then kill it sudo java -jar server.jar --nogui & sleep 10 pkill -f server.jar # Accept the EULA echo 'eula=true' | sudo tee eula.txt # Create a user and group for Minecraft sudo adduser --system --home /opt/minecraft minecraft sudo groupadd minecraft sudo adduser minecraft minecraft # Assign ownership of the Minecraft directory to the Minecraft user sudo chown -R minecraft:minecraft /opt/minecraft # Create the systemd service file echo '[Unit] Description=start and stop the minecraft-server [Service] WorkingDirectory=/opt/minecraft User=minecraft Group=minecraft Restart=on-failure RestartSec=20 5 ExecStart=/usr/bin/java -Xmx16384M -Xms16300M -jar server.jar --nogui [Install] WantedBy=multi-user.target' | sudo tee /etc/systemd/system/minecraft.service # Reload the system daemon, enable, and start the service sudo systemctl daemon-reload sudo systemctl enable minecraft.service sudo systemctl restart minecraft.service sudo journalctl -fu minecraft.service

After you run this script, you will see some logs that look like this:

No existing world data, creating new world Loaded 7 recipes Loaded 1271 advancements Starting minecraft server version 1.20.4 Loading properties Default game type: SURVIVAL Generating keypair Starting Minecraft server on *:25565 Using epoll channel type Preparing level "world" Preparing start region for dimension minecraft:overworld Preparing spawn area: 0% Preparing spawn area: 0% Preparing spawn area: 0% Preparing spawn area: 0% Preparing spawn area: 0% Preparing spawn area: 1% Preparing spawn area: 2% Preparing spawn area: 97% Time elapsed: 25295 ms Done (31.325s)! For help, type "help"

And that’s it! You can now put the IP of your server into your Minecraft launcher:

<ip address of server>:25565

You should be able to connect and start playing!

Notice that since we created a service file, this Minecraft server will restart whenever the machine reboots.

The script is relatively easy to understand.

One thing to note:

-Xmx16384M -Xms16300M

Are used for setting the Max RAM and Min Ram. Here I have 16 GB as max and just under 16 GB as min.

Hopefully this is helpful. You can also port forward the private IP and port of the server so that you and your friends can use it outside of your home network. Be careful on that, make sure you have a firewall. Open ports are bad.

Cheers,

Joe

ncG1vNJzZmiinZi0rbvCpGWsrZKowaKvymeaqKVfpXypu9Zmq6hloqq7bq2MpqCnnZOnrqfAjKycq66Vp3qwug%3D%3D

Filiberto Hargett

Update: 2024-12-03