notes/Setting up a Minecraft server.md
2023-07-23 08:45:03 -06:00

2.9 KiB

Preamble

This guide assumes some basic knowledge of Linux and package managers.

At minimum, a minecraft server requires Java, the minecraft server jar or an alternative server (spigot, lithium), and the ability to port forward and allow programs through your firewall.

Installing Java

As of 2023-07, Minecraft requires Java 17 to run version 1.20.1. You may need to look for a later version. Don't install the default version of Java in the repos of your chosen distro, it's very often out of date, and probably won't work with minecraft. You're going to look for any package that contains the JRE (Java Runtime Environment) or JDK (Java Development Kit). Both contain the Java Virtual Machine (JVM) and the ability to run Java programs. I like AdoptOpenJDK, but any distribution of Java that fits the version requirements will work sufficiently.

  • Prior to installation, be sure to remove a java installation if it exists on your system. You can see if java is present on your distro with java --version.

The format of the install command will change depending on the Java version, distro repositories and package manager, but this is what you'd run to install Java 17 on Debian 12:

sudo apt install openjdk-17-jre-headless

Setting up a location for the server

I like to have the minecraft server jar in /opt/minecraft (/opt is for non-user specific programs that don't go in any of the /bin folders), accessible by a minecraft group.

# Make a new folder named `minecraft` in `/opt`
sudo mkdir /opt/minecraft
# Create a new group named `minecraft`
sudo groupadd minecraft
# Add your user to it (You may need to reload your user session)
sudo usermod -aG minecraft your-username-here
# Make it so that the minecraft group owns that folder
sudo chgrp minecraft /opt/minecraft
# Make it so that:
# The user that owns the folder has read, write, and execute perms
# The group that owns the folder has read, write, and execute perms
# Anyone not in the above categories can read, but not write or execute
sudo chmod 775 /opt/minecraft

Downloading the server jar into /opt/minecraft:

cd /opt/minecraft
# Go to https://www.minecraft.net/en-us/download/server,
# and copy the link for "Download server.[version].jar:
wget 


This enables minecraft to run in the background, restart if it crashes, etc etc.

In /etc/systemd/system, place this file and tailor it to your liking.

[Unit]
Description=Minecraft Servre
# I don't know what these mean I'm getting them from here:
# https://gist.github.com/dotStart/ea0455714a0942474635
Wants=network-online.target
After=network-online.target

[Service]
# If wanted, you can set a particular group or user to run the service under
# User=foo
# Group=bar

# This command is run when the service is started
|ExecStart=/usr/bin/java -Xmx8G -Xms3g -jar /path/to/server.jar --nojline --noconsole