skip to content
Maathuran's Blog
Setting up Minecraft (PaperMC) on Alpine VM

Setting up Minecraft (PaperMC) on Alpine VM

/ 5 min read

Introduction

We will set up an Alpine Server running Minecraft (PaperMC Engine) hosted on one of our Proxmox Nodes.

Installing Alpine

Refer to Setting up Docker on Proxmox 8.0 if you need help Downloading and setting up Alpine.

Value
Nodepve03
VM ID102
NameMinecraft
ISO Imagealpine-virt-3.18.4-x86_64.iso
Disk Size64 GiB
CPU Cores4
TypeHost
Memory12288 MiB
IP10.0.210.102
Subnet255.255.0.0
Gateway10.0.0.1
Nameservers1.1.1.1

Adding Community Repo

After SSH’ing into your Alpine, run apk update and apk upgrade to update the system. To add the community repo, run the following command

cat > /etc/apk/repositories << EOF; $(echo)

https://dl-cdn.alpinelinux.org/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/main/
https://dl-cdn.alpinelinux.org/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/community/
https://dl-cdn.alpinelinux.org/alpine/edge/testing/

EOF

then

apk update

Installing OpenJDK

To add OpenJDK, type in the following apk add openjdk20, and you will get the following in the output. It will take some time as the packages are large

mc:~# apk add openjdk20
(1/32) Installing java-common (0.5-r0)
(2/32) Installing libffi (3.4.4-r2)
(3/32) Installing p11-kit (0.24.1-r2)
(4/32) Installing libtasn1 (4.19.0-r1)
(5/32) Installing p11-kit-trust (0.24.1-r2)
(6/32) Installing ca-certificates (20230506-r0)
(7/32) Installing java-cacerts (1.0-r1)
(8/32) Installing openjdk20-jre-headless (20.0.2_p9-r0)
(9/32) Installing libxau (1.0.11-r2)
(10/32) Installing libmd (1.0.4-r2)
(11/32) Installing libbsd (0.11.7-r1)
(12/32) Installing libxdmcp (1.1.4-r2)
(13/32) Installing libxcb (1.15-r1)
(14/32) Installing libx11 (1.8.7-r0)
(15/32) Installing libxext (1.3.5-r2)
(16/32) Installing libxi (1.8.1-r0)
(17/32) Installing libxrender (0.9.11-r3)
(18/32) Installing libxtst (1.2.4-r2)
(19/32) Installing alsa-lib (1.2.9-r1)
(20/32) Installing brotli-libs (1.0.9-r14)
(21/32) Installing libbz2 (1.0.8-r5)
(22/32) Installing libpng (1.6.39-r3)
(23/32) Installing freetype (2.13.0-r5)
(24/32) Installing giflib (5.2.1-r4)
(25/32) Installing libjpeg-turbo (2.1.5.1-r3)
(26/32) Installing lcms2 (2.15-r2)
(27/32) Installing openjdk20-jre (20.0.2_p9-r0)
(28/32) Installing openjdk20-jmods (20.0.2_p9-r0)
(29/32) Installing openjdk20-jdk (20.0.2_p9-r0)
(30/32) Installing openjdk20-demos (20.0.2_p9-r0)
(31/32) Installing openjdk20-doc (20.0.2_p9-r0)
(32/32) Installing openjdk20 (20.0.2_p9-r0)
Executing busybox-1.36.1-r4.trigger
Executing java-common-0.5-r0.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 357 MiB in 91 packages
mc:~# 

To test if it is installed, type java -version and see if you get this

openjdk version "20.0.2" 2023-07-18
OpenJDK Runtime Environment (build 20.0.2+9-alpine-r0)
OpenJDK 64-Bit Server VM (build 20.0.2+9-alpine-r0, mixed mode, sharing)

Installing PaperMC

Create a new folder called Minecraft and navigate into it.

mkdir minecraft
cd minecraft/

use wget to install the latest PaperMC Version

wget https://api.papermc.io/v2/projects/paper/versions/1.20.1/builds/125/downloads/paper-1.20.1-125.jar -O paper.jar

Then launch OpenJDK with PaperMC.jar

java -Xms2G -Xmx2G -jar paper.jar --nogui

the first time it launches, you will get an error asking to accept the EULA

mc:~/minecraft# java -Xms2G -Xmx2G -jar paper.jar --nogui
Downloading mojang_1.20.1.jar
Applying patches
Starting org.bukkit.craftbukkit.Main
System Info: Java 20 (OpenJDK 64-Bit Server VM 20.0.2+9-alpine-r0) Host: Linux 6.1.60-0-virt (amd64)
Loading libraries, please wait...
[23:48:35 INFO]: Could not find existing server.properties. Creating with default values...
[23:48:35 WARN]: Failed to load eula.txt
[23:48:35 INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
mc:~/minecraft# 

Use vi to edit eula.txt and change line 3 to true. After that, rerun the jar file

mc:~/minecraft# java -Xms2G -Xmx2G -jar paper.jar --nogui
Starting org.bukkit.craftbukkit.Main
System Info: Java 20 (OpenJDK 64-Bit Server VM 20.0.2+9-alpine-r0) Host: Linux 6.1.60-0-virt (amd64)
Loading libraries, please wait...
[23:51:40 INFO]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD'
[23:51:40 INFO]: Found new data pack file/bukkit, loading it automatically
[23:51:42 INFO]: Loaded 7 recipes
[23:51:42 INFO]: Starting minecraft server version 1.20.1
[23:51:42 WARN]: ****************************
[23:51:42 WARN]: YOU ARE RUNNING THIS SERVER AS AN ADMINISTRATIVE OR ROOT USER. THIS IS NOT ADVISED.
[23:51:42 WARN]: YOU ARE OPENING YOURSELF UP TO POTENTIAL RISKS WHEN DOING THIS.
[23:51:42 WARN]: FOR MORE INFORMATION, SEE https://madelinemiller.dev/blog/root-minecraft-server/
[23:51:42 WARN]: ****************************
[23:51:42 INFO]: Loading properties
[23:51:42 INFO]: This server is running Paper version git-Paper-125 (MC: 1.20.1) (Implementing API version 1.20.1-R0.1-SNAPSHOT) (Git: 93829bb)
[23:51:42 INFO]: Using 4 threads for Netty based IO
[23:51:42 INFO]: Server Ping Player Sample Count: 12
[23:51:42 INFO]: [ChunkTaskScheduler] Chunk system is using 1 I/O threads, 1 worker threads, and gen parallelism of 1 threads
[23:51:42 WARN]: [!] The timings profiler has been enabled but has been scheduled for removal from Paper in the future.
    We recommend installing the spark profiler as a replacement: https://spark.lucko.me/
    For more information please visit: https://github.com/PaperMC/Paper/issues/8948
[23:51:43 INFO]: Default game type: SURVIVAL
[23:51:43 INFO]: Generating keypair
[23:51:43 INFO]: Starting Minecraft server on *:25565
[23:51:43 INFO]: Using epoll channel type
[23:51:43 INFO]: Paper: Using libdeflate (Linux x86_64) compression from Velocity.
[23:51:43 INFO]: Paper: Using OpenSSL 3.0.x (Linux x86_64) cipher from Velocity.
[23:51:43 INFO]: Preparing level "world"
[23:51:54 INFO]: Preparing start region for dimension minecraft:overworld
[23:51:54 INFO]: Time elapsed: 97 ms
[23:51:54 INFO]: Preparing start region for dimension minecraft:the_nether
[23:51:54 INFO]: Time elapsed: 71 ms
[23:51:54 INFO]: Preparing start region for dimension minecraft:the_end
[23:51:54 INFO]: Time elapsed: 49 ms
[23:51:54 INFO]: Running delayed init tasks
[23:51:54 INFO]: Done (12.348s)! For help, type "help"
[23:51:54 INFO]: Timings Reset
> 

After the world generation is complete, you can connect to the world from Minecraft. MC1

[23:56:02 INFO]: UUID of player Maathuran is ee532861-c485-4cd0-a2d1-8561aa91e2b1
[23:56:02 INFO]: Maathuran joined the game
[23:56:02 INFO]: Maathuran[/10.0.0.61:53674] logged in with entity id 308 at ([world]113.5, 64.0, -9.5)
> 

Creating an OpenRC init file

Using your favorite text edior, make a new file nano /etc/init.d/papermc with the following

#!/sbin/openrc-run

description="Start minecraft server"
command="/usr/bin/java"
command_args="-Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar --nogui"
pidfile="/run/${RC_SVCNAME}.pid"
command_background=true
directory="/root/minecraft"

Save the file and make it executable with chmod 755 /etc/init.d/papermc, then add the file to OpenRC with rc-update add papermc, after that you can start it with rc-service papermc start

Layer 3 Proxy with Caddy

With Caddy, add the following to enable port 25565 to be forwarded to the Minecraft server.

{
    "apps": {
        "layer4": {
            "servers": {
                "T25565": {
                    "listen": [
                        "tcp/0.0.0.0:25565"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "handler": "proxy",
                                    "upstreams": [
                                        {
                                            "dial": [
                                                "tcp/10.0.210.102:25565"
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        }
    }
}