Minecraft Linux Server
Short tutorial to get a Minecraft server up and running on Linux.
Installing Minecraft and Dependencies
Minecraft java edition runs on, well, java. In order to get the server up and running ensure that you have the Java Runtime Environment installed. You may not be able to install the JRE on its own, just depends on your distribution. If that is the case the JRE comes with any installation of the Development Kit.
Examples are assuming you have a Debian based Linux distribution using the
aptpackage manager. Please use your provided distribution’s package manager and its syntax.
Use the command below to check if openjdk is installed. If not use the second command to install it. At the time of writing Minecraft uses openjdk version 21:
1
2
3
sudo apt list --installed | grep openjdk
sudo apt install openjdk-21-jdk-headless -y
If you are using a server OS like myself you will want the headless version meaning it will NOT come with a GUI. I have never tried nor will I go over how to use the version of the JDK that comes with a built-in UI.
Vanilla Server v.s. Alternatives
Once you have java installed it is time to decide what version of the Minecraft server you want to use. There are many different options nowadays. Regardless of what you choose the initial setup process is the same for them all. Some will give more features than others and all of the different versions made by the community improve performance of the server. Regardless of whether you plan to use the extended features offered by the community, I recommend you pick one of them purely for the performance improvements. Although, if you only plan to have a few players on at a time it is not necessary. If you are interested I have a list of many of the more popular versions below:
Installation and systemd
After making your decision on what version of the Minecraft server to use download the .jar file. For simplicity later on rename the file something easy to remember like server.jar.
You need a folder on the server for your game files to reside. For example I have mine stored under ~/minecraft/server/. Once you have chosen a folder move/upload the .jar file to that location on your server. From here we need to write and run a script that will initialize the server. Copy the below text into a new text file, name it what you like, and save it with the .sh extension.
Note that the -Xmx and -Xms flags will tell java the maximum and minimum amount of ram it can use while running the serer. In this instance they are defined in megabytes. You can see the recommended systems requirements here.
1
/usr/bin/java -Xmx8192M -Xms1024M -jar server.jar nogui
Once the file is created make it executable using chmod and run the file with ./start-server.sh. Even if everything was done correctly, it won’t get very far and will immediately shutdown. During the first launch it will create a eula.txt file in the same directory as your server.jar and start script. Set the value within to eula=true to accept the End User License Agreement and your server will fully function when started up from here on out.
To start the server using systemd you will need a unit file. Below is my configuration. Place the file in /etc/systemd/system/. Name the file whatever you like so long as it has the .service extension i.e. minecraft.service.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Minecraft Server
After=network.target
[Service]
Restart=on-failure
RestartSec=10
User=USER
WorkingDirectory=/PATH/TO/SERVER/FILES/
ExecStart=/usr/bin/java -Xmx8192M -Xms1024M -jar server.jar nogui
[Install]
WantedBy=multi-user.target
Replace “USER” with the user you want the service to run under, and change the “WorkingDirectory” path to that of your server installation. Then assuming you named the file minecraft.service use sudo systemctl enable minecraft to enable systemd to automatically start the service on boot. Use sudo systemctl start minecraft to start up the service for the very first time, from here on out you won’t have to touch it unless updating or configuring game files. All basic server configuration is done within the server.properties file. If you chose a community version of the Minecraft server, they have their own specific configuration you can play around with as well. For example Spigot has the spigot.yml file. To shutdown the server for a version update or if you wish to edit the config files us sudo systemctl stop minecraft make the necessary changes and start the server again with sudo systemctl start minecraft.
You are just about done and ready to play the final touches will be:
- Open port
25565on your systems firewall (if the firewall is enabled) - Port forward the same port through your gateway to your host machine (if hosted locally)
- Give the public Ip assigned to your machine (if hosted in the cloud) or the public Ip of your home networks gateway (if hosted locally) to players
- Enter that Ip address into the correct field within Minecraft and you are all set!
