Installation

Step-by-step setup on a fresh Ubuntu 22.04 or 24.04 host.

1. Install Docker

sudo apt update
sudo apt install -y ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
    sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

sudo usermod -aG docker "$USER"
newgrp docker
docker run --rm hello-world

2. Clone the repo

git clone https://github.com/MrGuato/valheim-game-server.git
cd valheim-game-server
chmod +x valheim

3. Run setup

./valheim setup

The wizard asks for the server name, world name, password, public listing, crossplay and time zone. It writes .env (mode 600) and creates config/, data/, backups/ and logs/ owned by UID 1000.

Valheim enforces two password rules: at least 5 characters, and the password must not appear inside the server name. The wizard checks both.

To skip the wizard:

cp .env.example .env
nano .env
mkdir -p config data backups logs
sudo chown -R 1000:1000 config data

4. Open the firewall

On the host:

sudo ufw allow 2456:2457/udp
sudo ufw allow 2458/udp    # only if CROSSPLAY=true

On your router, forward UDP 2456-2457 (and 2458 for crossplay) to the host. Restrict the forward to your friends’ IPs if you do not need to appear in the public server list.

5. Start the server

./valheim start

That pulls the image from GHCR, starts the container and tails the logs. The first start downloads about 2.2 GB of game files through SteamCMD. When you see this, the world is loaded:

[valheim] Starting: name='...' world='...' port=2456 (public, crossplay=false)
...
Game server connected

6. Connect

Direct connect from the Valheim main menu with your.public.ip:2456, or find the server in the community list when SERVER_PUBLIC=true.

Note: if you forwarded the ports for specific IPs only, the server will not show up in the public list even with SERVER_PUBLIC=true. Use direct connect.

Optional: build the image locally

./valheim build
IMAGE_REPOSITORY=valheim-game-server IMAGE_TAG=dev ./valheim start

Optional: scheduled backups

crontab -e
30 9 * * 0 cd /home/you/valheim-game-server && ./valheim backup >> logs/backup.log 2>&1

See Backups.

Updates

Watchtower (in docker-compose.yaml) checks for a new image every night at 05:00 server time and recreates the container when there is one. To update right away, run git pull && ./valheim update on the host.


Built by MrGuato. MIT licensed. Not affiliated with Iron Gate or Coffee Stain.

This site uses Just the Docs, a documentation theme for Jekyll.