This is a brief guide on how to:

  • Set up a Valheim Dedicated Server on Ubuntu
  • Migrate existing Valheim worlds to your new server
  • Troubleshoot server connection issues

This guide was created while using Ubuntu 20.04 (LTS). Your experience may vary depending on Linux distro.

Setting up Valheim Dedicated Server

Instead of going down the route of manually setting up SteamCMD, LinuxGSM can help us tremendously. Follow the instructions for installing vhserver here.

For convenience, I’ll share the steps that I took. Please make sure to review the link above because this post may not be up to date for long.

Installation steps

  1. Install the vhserver dependencies.
    $ sudo dpkg --add-architecture i386; sudo apt update; sudo apt install curl wget file tar bzip2 gzip unzip bsdmainutils python util-linux ca-certificates binutils bc jq tmux netcat lib32gcc1 lib32stdc++6 steamcmd

  2. Create a new user to run the server on.
    # adduser vhserver

  3. (Optional) Remove the password for vhserver user. Then we can use su to access the account and don’t have to worry about password strength.
    # passwd -d vhserver

  4. Start a new session as vhserver.
    # su - vhserver

  5. Download linuxgsm.sh.
    $ wget -O linuxgsm.sh https://linuxgsm.sh && chmod +x linuxgsm.sh && bash linuxgsm.sh vhserver

  6. Run the installer and follow the onscreen instructions.
    $ ./vhserver install

  7. If you saw any missing dependencies when running the install command, the installer should provide you with a command to fetch those dependencies. Run this command as a sudoer/root.

Once you’ve completed the setup, you should be able to test out your server by running the following command (as vhserver user):
$ ./vhserver start

Network configuration

I would highly recommend configuring your server firewall as well.

# ufw allow 2456:2568/tcp
# ufw allow 2456:2568/udp
# ufw enable

To connect to your server, use the correct port for your connection method:
Port 2456 will be used when connecting via the in-game server browser (using “Join IP” option).
Port 2457 will be used when connecting via Steam’s Server Browser (Steam -> View -> Servers).


Migrating existing Valheim worlds to your new server

First off, identify where your world save is currently located. If you have Valheim installed on Windows, your save files live here:
C:\Users\%USERNAME%\AppData\LocalLow\IronGate\Valheim\worlds

Also important to know is that the Linux world save location is different and it will not be created until vhserver is run for the first time. If you skipped to this point in the guide, you will likely have to manually create the folder. The save files live here:
/home/vhserver/.config/unity3d/IronGate/Valheim/worlds

Zip up the files in that folder and move them from one location to the other. You’re looking for the following files:
%worldname%.db, %worldname%.db.old, %worldname%.fwl, %worldname%.fwl.old

To make sure that vhserver is using your migrated world and not a default one, append the following lines to the common.cfg file.
$ vim /home/vhserver/lgsm/config-lgsm/vhserver/common.cfg

servername="%exampleServer%"
serverpassword="%examplePassword%"
gameworld="%worldname%"

Next time you run ./vhserver start, you should be good to go!


Not enough RAM?

Just download more!

If RAM is becoming a bottleneck on your VM but you can’t/don’t want to increase resources, you can give yourself an additional buffer by adding swap space.

First check if you already have swap enabled:
# swapon --show (prints swap list = yes | empty output = no)

If you don’t have existing swap space, create a swap file. I chose a size of 2G but you may want to tweak to fit your needs.

# fallocate -l 2G /swapfile
# chmod 600 /swapfile
# mkswap /swapfile
# swapon /swapfile

(Optional) Make sure this change persists by adding the following line to /etc/fstab:

/swapfile swap swap defaults 0 0

Digital Ocean fix

Having trouble connecting a Valheim client to the server? Checked that you can access your server remotely and firewall settings aren’t getting in the way? If so, you probably need to edit your droplet’s Netplan configuration.

  1. Open the Netplan config file as a sudoer/root.
    # vim /etc/netplan/50-cloud-init.yaml
  2. Remove the private IP address under eth0 (10.x.x.x)
  3. Apply the netplan config as a sudoer/root.
    # netplan apply
  4. Reboot your server.

credit to: Somuchtogrok

I ran into this issue when using a DigitalOcean droplet to host this server. Not knowing how resource-intensive Valheim hosting would be, I chose the cheapest droplet available to test. I ended up upgrading the droplet to have 2 vCPUs and 2GB RAM. I was having issues reaching the Valheim server via in-game server browser and the Steam Server Browser. However, I was also currently in a remote SSH session and my firewall settings looked correct, so it was unclear what might be causing the issue. I increased the droplet vCPU and RAM because I thought it might have been contributing. I ran ./vhserver debug and wasn’t sure if the server was just choking my limited resources since output was not being consistently printed in the terminal. Ran into the above fix on a reddit thread and it worked perfectly.