How to install a Minecraft server (Java Edition) on Ubuntu 24.04 LTS.
Yesterday, Eli told me 100 random people were on our Minecraft server. Incidentally I set the server limit to 100. One of the players told him it was advertised on a server list.
That’s odd because this is a private Minecraft server and we have enabled the player white-list. We tested it so I know it worked before. Somehow between updates the white-list broke. We’ve been using AMP to manage the MC servers, but Eli and I couldn’t figure out what combinations of toggles🕹️ , knobs 🎛️, buttons 🔘, and sliders 🎚️we needed to set to get the white-list working again. This is very simple to do on the command line–simply set white-list=true
in server.properties
and add the players to the whitelist.json
file. But in the GUI we couldn’t figure out how to make that happen. I did figure out that in some places white-list in AMP refers to the server JAR files so we blocked the whole server from starting.
It was at this point I decided the command line interface is easier.
Design decisions:
- As simple as possible
- Use the shell instead of web interface. GUI interfaces seem to create more maintenance and problems than just using a CLI.
- Abstract Java and Minecraft server installation and updating with snap.
- Use crontab for auto-start (systemd would be the proper way to do this, but this is fast and minimizes complexity).
- Self hosted. This gets very intermittent use so I don’t want to pay hundreds of dollars a month for a hosted solution, but when it’s used it needs some CPU. I tried to use usage based cloud instances but found them too sluggish, too expensive, or not near our region (high latency). I found 4 cores and 6GB memory in a Proxmox VM does well.
- Keep everything vanilla. No mods means fewer things that can break and not having to do builds to upgrade. If we run into issues I may switch to SpigotMC or such but currently it seems stable.
This setup uses James Tigert’s mc-server-installer snap to install Minecraft server, an expect script (your grandfather’s RPA) to interact with the startup menu, and cron to start the service on system boot.
Install mc-server-installer, and expect
$ sudo su
# snap install mc-server-installer
# apt install expect
# adduser minecraft
# su minecraft
$ cd ~
$ mc-server-installer
------------------------------------------
MINECRAFT SERVER INSTALLER
MENU
------------------------------------------
ATTENTION: Latest available version: 1.21
Select from the following options:
1) Download latest (v1.21) server.jar
2) Agree to the EULA
3) Edit the server.properties file
4) Run MC server with max 2GB of RAM
5) Run MC server with max 4GB of RAM
6) Run MC server with max 6GB of RAM
7) Run MC server with max 8GB of RAM
8) Run MC server with max 16GB of RAM
9) View README
10) Back up your world
11) Run custom RAM settings
12) Run custom jar file and RAM settings
13) Quit
Choice:
Choose Option 1 to download the server.jar, re-run and choose 2 to agree to the EULA, re-run and choose 3 to edit server.properties (if needed), re-run and choose an option depending on your memory requirements. At this point verify you are able to connect to the Minecraft server. If it’s working CTRL+C to kill it.
If you want to modify the server.properties and world files directly, look under /home/minecraft/snap/mc-server-installer/current
Create an Expect Script to Interact with the Menu
$ vim /home/minecraft/start_minecraft.sh
On line 9, I’m sending menu option “6”, but you can change it depending on your memory configuration.
#!/usr/bin/expect -f
set timeout -1
log_file /home/minecraft/minecraft.log
log_user 1
spawn mc-server-installer
expect {
"Choice: " {
send "6\r"
exp_continue
}
timeout {
puts "Error: Timeout"
exit 1
}
eof {
puts "Error: EOF"
exit 1
}
}
Set executable bit…
$ chmod 755 /home/minecraft/start_minecraft.sh
I suggest running the script once to make sure it works…
$ ./start_minecraft.sh
(CTRL+C to kill it).
Add cron job to autostart Minecraft server on reboot
$ crontab -e
Add the following entry to crontab…
@reboot sleep 10 && export TERM=xterm && /home/minecraft/start_minecraft.sh
Reboot the Ubuntu server.
Tail the log to make sure it starts…
# sudo su minecraft
# tail -F ~/minecraft.log
And now you can connect to the Minecraft server.
After moving all the world and all the files over, the whitelist just worked out of the box on our new Minecraft servers.
This is sooo funnny. I just got your email and now I come to your website to just see that both of use did the same thing almost on the same day, but at least in the same week. Funny it is, isn’t it?
Well how about that! I’m curious what solution you came up with for auto-start on boot? Did you end up using systemd?
This worked great! Thanks for the howto.
You’re welcome!