Building Bedrock Server [Ubuntu24.04.3]

This guide explains how to build a Minecraft Bedrock Edition server on Ubuntu.

Preparation

Install unzip and tmux.

Warning

Since screen is now deprecated, we recommend using tmux.

sudo apt update
sudo apt install unzip tmux

Next, open port 19132 for the server to use. To reduce lag, use UDP.

sudo ufw allow 19132/udp
sudo ufw reload

Create a server management user.

Since you’ll be switching users frequently, a short username is easier. This time, I chose “mc”.

sudo adduser mc

Switch the user to mc and create the server directory.

su - mc
mkdir bedrock

Download

https://www.minecraft.net/en-us/download/server/bedrock

Download the server from the official website.
Check the boxes for “Ubuntu (Linux)” and “I agree to the Minecraft End User License Agreement and Privacy Policy” then click “Download.”

Information

By changing the version part of the download link”https://www.minecraft.net/bedrockdedicatedserver/bin-linux/bedrock-server-1.21.114.1.zip“, you can also download older server versions.

List of past versions → Bedrock Dedicated Server – Minecraft Wiki

Once the download is complete, move the file to the directory you created earlier. If you downloaded it on another PC, transfer the file using a USB drive or SSH.

Specify the directory and then unzip.

cd bedrock
unzip bedrock-server-x.xx.xxx.x.zip -d ./server

Confirm the operation

After unzipping the files, run ./bedrock_server within the directory.

When joining a server,
go to “Play” → “Servers” → “Add Server” → enter the IP address or domain name of your server in “Server Address”.

Warning

To stop the server, enter “stop” to shut it down.

Server Management Script

Closing the terminal where the server is running will also stop the server, so we’ll use tmux to run it in the background.
However, entering commands to manage the server manually is quite annoying.
Therefore, I referenced the script from the following site. It’s a script that manages starting, stopping, and backing up the site’s server all at once. Honestly, this site is easier to understand than mine.

nano script.sh
chmod 744 script.sh

I’ll make a few changes to the content.

#!/bin/bash
#
# bedrock_server start/stop/backup script
#

# bedrock_server user
USERNAME='mc'

# session name
SESSION_NAME='bedrock'

# bedrock_server installation directory
BEDROCK_PATH='/home/mc/bedrock/server'

# LD_LIBRARY_PATH setting
LD_LIBRARY_PATH="$BEDROCK_PATH"

# execute bedrock_server
SERVICE="$BEDROCK_PATH/bedrock_server"

## backup settings
# Backup base directory
BK_PATH='/home/mc/bedrock'

# Backup storage directory
BK_DIR="$BK_PATH/bedrock_backup"

# Backup acquisition time
BK_TIME=`date +%Y%m%d-%H%M%S`

# Full Backup Data Name
FULL_BK_NAME="$BK_DIR/bedrock_full_backup_${BK_TIME}.tar.gz"

# Simple Backup Data Name
SIMPLE_BK_NAME="$BK_DIR/bedrock_simple_backup_${BK_TIME}.tar"

# Data Subject to Simple Backup
BK_FILE="./bedrock-server/worlds \
./bedrock-server/valid_known_packs.json \
./bedrock-server/permissions.json \
./bedrock-server/server.properties \
./bedrock-server/allowlist.json"

# Backup Data Retention Days
BK_GEN="3"

cd $BEDROCK_PATH

if [ ! -d $BK_DIR ]; then
    mkdir $BK_DIR
fi

ME=`whoami`

if [ $ME != $USERNAME ]; then
    echo "Please run the $USERNAME user."
    exit
fi

# Start
start() {
    if pgrep -u $USERNAME -f $SERVICE > /dev/null; then
        echo "$SERVICE is already running!"
    else
        echo "Starting $SERVICE..."
        tmux new-session -d -s $SESSION_NAME
        tmux send-keys -t $SESSION_NAME:0 "LD_LIBRARY_PATH=$LD_LIBRARY_PATH $SERVICE" C-m
    fi
}

# Stop
stop() {
    if pgrep -u $USERNAME -f $SERVICE > /dev/null; then
        echo "Stopping $SERVICE"
        tmux send-keys -t $SESSION_NAME:0 "say SERVER SHUTTING DOWN IN 30 SECONDS." C-m
        sleep 30
        tmux send-keys -t $SESSION_NAME:0 "stop" C-m
        sleep 10
        echo "Stopped bedrock_server"
    else
        echo "$SERVICE is not running!"
        exit
    fi
    while :
    do
        if
            pgrep -u $USERNAME -f $SERVICE > /dev/null; then
            echo "Stopping $SERVICE"
            sleep 10
        else
            tmux kill-session -t $SESSION_NAME
            echo "Stoped $SERVICE"
            break
        fi
    done
}

# Simple backup
s_backup() {
    if pgrep -u $USERNAME -f $SERVICE > /dev/null; then
        echo "Backup start minecraft data..."
        tmux send-keys -t $SESSION_NAME:0 "say SERVER SHUTTING DOWN IN 30 SECONDS. Saving map..." C-m
        sleep 30
        tmux send-keys -t $SESSION_NAME:0 "stop" C-m
        while :
        do
            if
                pgrep -u $USERNAME -f $SERVICE > /dev/null; then
                echo "Stopping $SERVICE"
                sleep 30
            else
                echo "Stopped bedrock_server"
                echo "Simple Backup start ..."
    	        tar cfv $SIMPLE_BK_NAME -C $BK_PATH $BK_FILE
                gzip -f $SIMPLE_BK_NAME
                echo "Simple Backup compleate!"
                find $BK_DIR -name "bedrock_simple_backup_*.tar.gz" -type f -mtime +$BK_GEN -exec rm {} \;
                break
            fi
        done
        echo "Starting $SERVICE..."
        tmux send-keys -t $SESSION_NAME:0 "$SERVICE" C-m
    else
        echo "Simple Backup start ..."
        tar cfv $SIMPLE_BK_NAME -C $BK_PATH $BK_FILE
        gzip -f $SIMPLE_BK_NAME
        echo "Simple Backup compleate!"
        find $BK_DIR -name "bedrock_simple_backup_*.tar.gz" -type f -mtime +$BK_GEN -exec rm {} \;
    fi
}

# Full backup
f_backup() {
    if pgrep -u $USERNAME -f $SERVICE > /dev/null; then
        echo "Full backup start minecraft data..."
        tmux send-keys -t $SESSION_NAME:0 "say SERVER SHUTTING DOWN IN 30 SECONDS. Saving map..." C-m
        sleep 30
        tmux send-keys -t $SESSION_NAME:0 "stop" C-m
        while :
            do
            if
                pgrep -u $USERNAME -f $SERVICE > /dev/null; then
                echo "Stopping $SERVICE"
                sleep 30
            else
                echo "Stopped bedrock_server"
                echo "Full Backup start ..."
    	        tar cfvhz $FULL_BK_NAME -C $BK_PATH ./bedrock-server
                echo "Full Backup compleate!"
                find $BK_DIR -name "bedrock_full_backup_*.tar.gz" -type f -mtime +$BK_GEN -exec rm {} \;
                break
            fi
            done
        echo "Starting $SERVICE..."
        tmux send-keys -t $SESSION_NAME:0 "$SERVICE" C-m
    else
        echo "Full Backup start ..."
        tar cfvhz $FULL_BK_NAME -C $BK_PATH ./bedrock-server
        echo "Full Backup compleate!"
        find $BK_DIR -name "bedrock_full_backup_*.tar.gz" -type f -mtime +$BK_GEN -exec rm {} \;
    fi
}

# Status check
status() {
    if pgrep -u $USERNAME -f $SERVICE > /dev/null; then
        echo "$SERVICE is already running!"
        exit
    else
        echo "$SERVICE is not running!"
        exit
    fi
}

case "$1" in
    start)
        echo "Bedrock Server Start"
        start
        ;;
    stop)
        echo "Bedrock Server Stop"
        stop
        ;;
    s_backup)
        echo "Simple Backup Start"
        s_backup
        ;;
    f_backup)
        echo "Full Backup Start"
        f_backup
        ;;
    status)
        echo "Bedrock Server Check Status"
        status
        ;;
    *)
        echo "Invalid option"
        echo "Usage: $0 {start|stop|s_backup|f_backup|status}"
esac

The usage is the same as the site I referenced.

When executing the script, specify start, stop, s_backup, f_backup, or status as arguments.

systemd

Configure settings for auto start. Enable management via the systemctl command. This configuration also references the site mentioned earlier.

exit
sudo nano sudo vi /etc/systemd/system/bedrock_server.service

Switch to the sudo user, then create the file.

[Unit]
Description=Minecraft Bedrock Server
After=network.target local-fs.target

[Service]
Type=forking
User=mⅽ
ExecStart=/home/mc/bedrock/server/script.sh start
ExecStop=/home/mc/bedrock/server/script.sh stop

[Install]
WantedBy=multi-user.target

Auto Start & Management

After creating the systemd file, register the service.

sudo systemctl enable bedrock_server.service

Next, we’ll set up cron to automatically run start → stop → full backup.
Before that, we’ll configure the system so that regular users (mc) can manage the server. Giving full permissions is risky, so we’ll restrict access to only the necessary commands.

sudo visudo

# Add the following
mc ALL=NOPASSWD: /bin/systemctl start bedrock_server, /bin/systemctl stop bedrock_server, /bin/systemctl restart bedrock_server

Switch to the mc and edit the cron file.

crontab -e

# Add the following

# Server shutdown at 2:00 AM daily
0 2 * * * sudo systemctl stop bedrock_servern
# Full backup at 2:10 AM daily
10 2 * * * /home/mc/bedrock/server/script.sh f_backup
# Server start at 3:00 AM daily
0 3 * * * sudo systemctl start bedrock_server

Leave a Reply

Your email address will not be published. Required fields are marked *