How to setup a Minecraft Server on Linux
This guide is for setting up a Minecraft server on a dedicated Linux server, I will assume you have already got to a point where the dedicated server is setup with whatever distro you chose.
Packages you will need installed
Make sure to choose headless versions of packages, this simply means they will not try and install gui packages as dependencies, we wont need a gui.
- java - This will most probably be in the form of a JDK or JRE
- tmux - Needed for the ability to detach the session
Java
- Minecraft ≥ 1.20.5 and 1.21 requires Java 21.
- Minecraft ≥ 1.18 requires Java 17.
- Minecraft ≥ 1.12 requires Java 8.
Set your path (For system wide "/etc/profile")
export JAVA_HOME="/usr/lib/jvm/jre-21-openjdk"
export PATH=$JAVA_HOME/bin:$PATH
Tmux
Tmux is essentially a terminal inside a terminal, normally if close a terminal or ssh session while something is running in the foreground, it will kill it.
When we run something inside tmux however, we can detach from the tmux session , sending it to the background.
To detach:
"ctrl+b" then "d"
To re-open that session:
"tmux a"
To start a tmux session:
"tmux"
Make sure to run your minecraft servers inside a tmux session.
Create a directory for your instance
I tend to like doing this in "/home" so for example: "/home/minecraft".
mkdir -p /home/minecraft
Completely Vanilla Install
You can get the current vanilla server Here
Creating a start server script is recommended.
This is a basic script to run a Vanilla server:
#!/bin/bash
maxram="4G"
server="minecraft_server.1.21.10.jar"
java -Xmx$maxram -Xms1024M -jar $server nogui
Make sure to run "chmod u+x start.sh" after creating the script. This will allow the script to be ran.
Modded Installs
More often than not when playing big curated modpacks, their server files will have everything you need to run the server. At most you will need to run "chmod u+x" on the start script to give it permission to run.
The following is for when you don't have a pre made script to install a pack.
Fabric Server Install
In my opinion this is one of the easiest modded servers to setup.
Most of the info you will need can be found on the fabric website: https://fabricmc.net/use/server
The launch command can easily be adapted into a script such as the one for the Vanilla install.
Forge and NeoForge Install
Get the download link for either neoforge or forge version and use wget or curl to download it to your server:
wget https://maven.minecraftforge.net/net/minecraftforge/forge/1.21.11-61.1.1/forge-1.21.11-61.1.1-installer.jar
curl -O https://maven.neoforged.net/releases/net/neoforged/neoforge/21.11.38-beta/neoforge-21.11.38-beta-installer.jar
Once you have the installer placed in the directory that you wish to install it in, run the following:
java -jar change-me-to-installer.jar --installServer
Once installed you are ready to add your mods.
Example start server script
#!/bin/bash
# Max Ram
ram="8G"
# java - can leave as default unless you wish to specify version
java="java"
# server jar
server="forge-server.jar"
# don't forget to accept the EULA or it won't boot
while true
do
$java -Xms1024M -Xmx$ram -jar $server nogui
echo "If you want to completely stop the server process now, press Ctrl+C before the time is up!"
echo "Rebooting in:"
for i in 12 11 10 9 8 7 6 5 4 3 2 1
do
echo "$i..."
sleep 1
done
echo "Rebooting now!"
done