Creating An Ubuntu Valheim Server

  • Post category:Uncategorized
  • Reading time:3 mins read

So i’ve been getting into Valheim quite a lot, some friends and I play quite a few games and this happens to be our game of choice. 

Naturally, they looked to me to get a server up and running, so this is kind of a reminder to myself of what i did, but also to help others build their own dedicated server using Linux.

Let’s Get Started!

I’m using Ubuntu 20.10 for this deployment. And i’m hosting the server through vultr.com.au (Here’s a referal link with some free stuff https://www.vultr.com/?ref=8813398-6G)

We’re assuming you have already updated and upgraded your server using apt-get update and apt-get upgrade

First thing we want to do is enable multiverse

vi /etc/apt/sources.list

Uncomment the following lines

deb-src http://us.archive.ubuntu.com/ubuntu groovy multiverse
deb-src http://us.archive.ubuntu.com/ubuntu groovy-updates multiverse

Now let’s run an update and upgrade again

sudo apt update && sudo apt upgrade

Create a new user steam and let’s install steamcmd

useradd -m steam
usermod -aG sudo steam
passwd steam
su - steam
apt-get install steamcmd

Once you have accepted the prompts, we will now install the Valheim server files using the below commands

cd /home/steam/
mkdir valheim
/home/steam/steamcmd +login anonymous +force_install_dir /home/steam/valheim +app_update 896660 validate +exit

Change into the valheim directory

cd /home/steam/valheim/

From here i used the scripts and tips from https://gameplay.tips/guides/9765-valheim.html

cp start_server.sh start_valheim.sh
vi start_valheim.sh
 #!/bin/bash

export templdpath=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH
export SteamAppId=892970

# Tip: Make a local copy of this script to avoid it being overwritten by steam.
# NOTE: Minimum password length is 5 characters & Password cant be in the server name.
# NOTE: You need to make sure the ports 2456-2458 is being forwarded to your server through your local router & firewall.
/home/steam/steamcmd +login anonymous +force_install_dir /home/steam/valheim +app_update 896660 +quit

./valheim_server.x86_64 -name "Server Name" -port 2456 -world "Dedicated" -password "passwordAbC" -public 1 > /dev/null &

export LD_LIBRARY_PATH=$templdpath

echo "Server started"
echo ""
#read -p "Press RETURN to stop server"
#echo 1 > server_exit.drp

#echo "Server exit signal set"
#echo "You can now close this terminal"

while :
do
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
echo "valheim.service: timestamp ${TIMESTAMP}"
sleep 60
done
vi valheim.service
 [Unit]
Description=Valheim service
Wants=network.target
After=syslog.target network-online.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=steam
WorkingDirectory=/home/steam/valheim
ExecStart=/home/steam/valheim/start_valheim.sh

[Install]
WantedBy=multi-user.target
sudo cp valheim.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl start valheim
sudo systemctl status valheim
 Now to enable Valheim every time the server starts up use
sudo systemctl enable valheim.service

Leave a Reply