Ultimate Guide to Setting Up a Valheim Server on Ubuntu

Ready to sail the seas of Valheim with your friends? This comprehensive guide will walk you through the process of setting up your own Valheim server on Ubuntu. Whether you’re a seasoned Linux user or new to server management, we’ve got you covered.

Prerequisites

Before we begin, ensure you have:

  1. An Ubuntu server (20.04 LTS recommended)
  2. Root or sudo access to your server
  3. At least 4GB of RAM (8GB recommended for smooth gameplay)
  4. At least 10GB of free disk space
  5. A stable internet connection

Need a reliable server to host your Valheim adventures? Check out Servers Guru for high-performance gaming servers at competitive prices.

Step 1: Port Forwarding and Firewall Configuration

Valheim requires specific ports to be open for optimal performance.

If you’re using UFW (Uncomplicated Firewall), open the necessary ports:

sudo ufw allow 2456/udp
sudo ufw allow 2457/udp
sudo ufw allow 2458/udp
sudo ufw allow 27060/udp

Note: If you’re using a cloud hosting provider like Servers Guru, you may need to configure these ports in their firewall settings as well.

Step 2: Set Up SteamCMD

First, let’s add the necessary repositories and architectures:

sudo add-apt-repository multiverse
sudo dpkg --add-architecture i386

Now, update your system and install SteamCMD:

sudo apt update && sudo apt install lib32gcc1 steamcmd -y

Step 3: Install Valheim Server Files

Create a directory for your Valheim server:

mkdir ~/valheim && cd ~/valheim

Install the Valheim server files:

/usr/games/steamcmd +login anonymous +force_install_dir /home/$USER/valheim +app_update 896660 validate +exit

Note: Replace $USER with your actual username if the above command doesn’t work.

Step 4: Create a Start Script

Create a start script for your Valheim server:

nano ~/valheim/start_valheim.sh

Paste the following content, making sure to customize the server name, world name, and password:

#!/bin/bash

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

/usr/games/steamcmd +login anonymous +force_install_dir /home/$USER/valheim +app_update 896660 +quit

./valheim_server.x86_64 -name "Your Server Name" -port 2456 -nographics -batchmode -world "Dedicated" -password "your_password" -public 1 > /dev/null &
export LD_LIBRARY_PATH=$templdpath

echo "Server started"

Make the script executable:

chmod +x ~/valheim/start_valheim.sh

Step 5: Create a Systemd Service

To run Valheim as a service, create a systemd service file:

sudo nano /etc/systemd/system/valheim.service

Paste the following content, replacing $USER with your actual username:

[Unit]
Description=Valheim server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10
StartLimitInterval=60s
StartLimitBurst=3
User=$USER
Group=$USER
ExecStartPre=/usr/games/steamcmd +login anonymous +force_install_dir /home/$USER/valheim +app_update 896660 validate +exit
ExecStart=/home/$USER/valheim/start_valheim.sh
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGINT
WorkingDirectory=/home/$USER/valheim
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target

Step 6: Start Your Valheim Server

Reload the systemd daemon and start the Valheim service:

sudo systemctl daemon-reload
sudo systemctl start valheim

To make the server start automatically on boot:

sudo systemctl enable valheim

Step 7: Manage Your Server

To check the status of your server:

sudo systemctl status valheim

To stop the server:

sudo systemctl stop valheim

To restart the server:

sudo systemctl restart valheim

Additional Configuration

Adding Admins

To add admins to your server, edit the adminlist.txt file:

nano ~/.config/unity3d/IronGate/Valheim/adminlist.txt

Add one Steam64ID per line.

Optimizing Your Valheim Server

For the best gaming experience, consider these tips:

  1. Allocate Sufficient Resources: Ensure your server has enough CPU and RAM. Servers Guru offers a range of high-performance options tailored for gaming.

  2. Regular Updates: Keep your server updated by running the start script, which includes the update command.

  3. Backup Your World: Regularly backup your world files located in ~/.config/unity3d/IronGate/Valheim/worlds/.

  4. Monitor Performance: Use tools like htop to monitor server resource usage.

Conclusion

Congratulations! You now have your own Valheim server up and running on Ubuntu. Remember, a great gaming experience starts with a reliable server. If you’re looking for top-notch performance and 24/7 support, consider hosting your Valheim server with Servers Guru.

May your adventures in Valheim be epic and your server always stable!