Setup a Team Fortress 2 Server on Arch Linux

Updated on November 21, 2023
Setup a Team Fortress 2 Server on Arch Linux header image

This tutorial explains how to setup a Team Fortress 2 server on Arch Linux. I assume that you are logged in with a non-root user account that has sudo access. This tutorial uses AUR to build packages, and that operation should not be performed from the root account.

Before You Begin

It is very important that you have the multilib repository enabled if and only if you are on a 64-bit (amd64) server. If it isn't enabled, then SteamCMD cannot run and you cannot even download the server files. To do this, you must uncomment the following lines in /etc/pacman.conf.

[multilib]
Include = /etc/pacman.d/mirrorlist

If you are on 32-bit (i686) Arch, you can safely ignore this.

Install SteamCMD

There is an AUR package for SteamCMD and it is one of the easiest ways to install SteamCMD on Arch. There are a couple odd things about it though:

  • All relative paths are relative to /usr/share/steamcmd.
  • To upgrade SteamCMD itself, you must be root.

If you are on a 64-bit server, you must install the package lib32-gcc-libs.

sudo pacman -Sy lib32-gcc-libs

Now we must build the package. Using curl, download the tarball for the package.

curl -O http://media.steampowered.com/installer/steamcmd_linux.tar.gz

Once the download finishes, extract and change to the directory created.

tar -xvzf steamcmd.tar.gz
cd steamcmd

Now, using makepkg, build the package.

makepkg -ci

If you didn't pass the -i flag to the makepkg command, use pacman to install it.

sudo pacman -U *.pkg.tar.xz

You now have SteamCMD installed and ready to download Team Fortress 2 server.

Install The Team Fortress 2 Server

This guide uses a separate user to run the server, so we will create a new tf2 user and group with it's own home folder in /var/lib.

sudo groupadd tf2
sudo mkdir /var/lib/tf2
sudo useradd -d /var/lib/tf2 -g tf2 -s /bin/bash tf2
sudo chown tf2.tf2 -R /var/lib/tf2

Now to install the server.

sudo -u tf2 steamcmd +login anonymous +force_install_dir ~tf2/server +app_update 232250 validate +quit

Once that finishes downloading, you have the server installed.

Configuring

Although you can run the server, some configuration should be done so that the server isn't too generic. The main file that we put settings in is the server.cfg file. Below is a very basic server.cfg file.

To open/create the file, use your favorite editor. Here vim is used, but you can use any text editor like nano.

sudo -u tf2 vim ~tf2/server/tf/cfg/server.cfg

Add the following. More settings can be found on the Team Fortress 2 wiki and Valve developer page. Be sure to change some of the settings to suit your needs.

hostname "Server Name"
rcon_password "password"
sv_password ""
sv_contact "email@example.com"
sv_tags ""
sv_region "255"
sv_lan "0"

exec banned_user.cfg
exec banned_ip.cfg
writeid
writeip

Running Your Server

It is known that you need a multiplexer like GNU Screen or tmux to run your server unattended. Here we are going to use tmux to run the server, but if you prefer and know how to use screen, feel free to use it.

Install tmux by using pacman.

sudo pacman -Sy tmux

You can start the server with the following command. You can change the map and maxplayers if desired.

sudo -u tf2 tmux new-session -d -s tf2-console -d '~tf2/server/srcds_run -console -game tf +map cp_dustbowl +maxplayers 24'

If you ever need to attach to the console, run the following.

sudo -u tf2 tmux attach -t tf2-console

You can leave the server console by typing CTRL + B then releasing those keys and then pressing D.

Running With systemd

Running the server with systemd is convenient for many reasons. The main one is that you can have it start when the VPS starts. This requires a script and a systemd unit to be written. Even though this is a good idea, it is optional.

The first thing to write is the start script. To create the script, use your favorite editor. Here vim is used, but you can use any text editor like nano.

sudo -u tf2 vim ~tf2/server/tf2.sh

Add the following.

#!/bin/sh

USER=$2

if [ -z $2 ]; then
  USER="tf2"
fi

case "$1" in
  start)
    sudo -u $ tmux new-session -d -s tf2-console -d '/var/lib/tf2/server/srcds_run -console -game tf +map cp_dustbowl +maxplayers 24'
    ;;
  
  stop)
    sudo -u $ tmux send-keys -t tf2-console 'say Server shutting down in 10 seconds!' C-m
    sleep 10
    sudo -u $ tmux send-keys -t tf2-console 'quit' C-m
    sleep 5
    ;;
  
  *)
    echo "Usage: $0  user"
esac

exit 0

Now you need to make the systemd unit. To create the unit, use your favorite editor. Here vim is used, but you can use any text editor like nano.

sudo vim /usr/lib/systemd/system/tf2.service

Add the following.

[Unit]
Description=Team Fortress 2 Server (SRCDS)
After=local-fs.target network.target

[Service]
ExecStart=/var/lib/tf2/server/tf2.sh start
ExecStop=/var/lib/tf2/server/tf2.sh stop
Type=forking

[Install]
WantedBy=multi-user.target

Now make sure the tf2.sh file is executable.

sudo chmod +x ~tf2/server/tf2.sh

After all that, you can use systemctl to start and stop the server. Also you can use it to make it start on boot.

To start:

sudo systemctl start tf2.service

To stop:

sudo systemctl stop tf2.service

To restart:

sudo systemctl restart tf2.service

To enable at boot:

sudo systemctl enable tf2.service

To disable at boot:

sudo systemctl disable tf2.service

Even though systemd is handling starting and stopping the server, you can still access the console with the following command:

sudo -u tf2 tmux attach -t tf2-console

Final Notes

SteamCMD is installed in an area where only root can change files (see note in "Install SteamCMD"). If you ever need to upgrade SteamCMD itself, just run it as root.

sudo steamcmd +quit

If you need to update the server. First stop the server and then use SteamCMD to update (using the same command to install).

sudo systemctl stop tf2.service
sudo -u tf2 steamcmd +login anonymous +force_install_dir ~tf2/server +app_update 232250 validate +quit
sudo systemctl start tf2.service

There are a lot more configuration topics that are not covered in this tutorial. If you need more information, please refer to the Team Fortress 2 Wiki and the Valve Developer Wiki.