Saltar al contenido
Set up a FiveM server on Linux

Set up a FiveM server on Linux

Run FXServer and txAdmin on Ubuntu or Debian: dependencies, a dedicated user, the Linux artifact, a systemd service or tmux, the ufw firewall and MariaDB.

Esta documentación está en inglés por ahora.

Last updated

This guide sets up FXServer with txAdmin on a fresh Ubuntu 22.04 / 24.04 or Debian 12 VPS. Other distributions work too, since the Linux artifact ships its own libraries in an alpine folder, but the package commands below are for Debian based systems. You need SSH access with a user that can run sudo.

Plays from youtube-nocookie.com after you click.

1. Update the system and install tools

Terminal
sudo apt update && sudo apt upgrade -y
sudo apt install -y xz-utils git curl wget tmux ufw

xz-utils is required to extract the artifact. git is for cloning resources, tmux for running the server in a detachable session, ufw for the firewall.

2. Create a user for the server

Never run a game server as root. Create a dedicated user and switch to it:

Terminal
sudo adduser --disabled-password --gecos "" fivem
sudo -iu fivem
mkdir -p ~/server
cd ~/server

Everything below runs as fivem unless it starts with sudo.

3. Download the Linux artifact

  1. Open https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/ in your browser.
  2. Pick the recommended build (check it on our Artifacts page) and copy the link to its fx.tar.xz.
  3. Download and extract it on the server:
Terminal
cd ~/server
wget https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/XXXXX-<hash>/fx.tar.xz
tar xf fx.tar.xz
rm fx.tar.xz
ls
# alpine  run.sh

Replace the URL with the one you copied. The build folder name changes with every release, so don’t reuse an old link from a tutorial.

4. Open the firewall

Allow SSH first so you don’t lock yourself out, then the game ports:

Terminal
sudo ufw allow OpenSSH
sudo ufw allow 30120/tcp
sudo ufw allow 30120/udp
# txAdmin web panel: better to allow only your own IP
sudo ufw allow from YOUR_HOME_IP to any port 40120 proto tcp
sudo ufw enable
sudo ufw status

If your home IP changes often, you can open 40120 to everyone (sudo ufw allow 40120/tcp), but then use a strong password and 2FA on every txAdmin account. See Security basics. Many VPS providers also have a firewall in their web panel: open the same ports there.

5. First start with txAdmin

Terminal
cd ~/server
bash run.sh

FXServer starts txAdmin and prints something like:

Text
[txAdmin] Use the PIN below to register:
[txAdmin]  1234
[txAdmin] http://YOUR_VPS_IP:40120/

Open that address in your browser on your own PC and follow the same steps as on Windows: Link Account with your Cfx.re login, create a backup password, pick a recipe, paste your license key, run the recipe, then Save & Run Server. The full walkthrough is in First setup and the deployer.

On Linux, txAdmin creates txData next to run.sh by default (~/server/txData). You can change it with the TXHOST_DATA_PATH environment variable.

Press Ctrl+C to stop it once setup is done. Next we make it run in the background.

6. Keep it running

Option A: tmux (simple)

Terminal
tmux new -s fivem
cd ~/server && bash run.sh

Detach with Ctrl+B then D. Reattach later with tmux attach -t fivem. The server keeps running after you log out, but not after a reboot. screen works the same way (screen -S fivem, detach with Ctrl+A then D, reattach with screen -r fivem).

Option B: systemd service (starts on boot)

Create the unit file as root:

/etc/systemd/system/fivem.service
[Unit]
Description=FiveM server (txAdmin)
After=network-online.target mariadb.service
Wants=network-online.target

[Service]
Type=simple
User=fivem
Group=fivem
WorkingDirectory=/home/fivem/server
ExecStart=/bin/bash /home/fivem/server/run.sh
Restart=on-failure
RestartSec=10
# Optional txAdmin settings, see the txAdmin env-config docs
# Environment=TXHOST_TXA_PORT=40120

[Install]
WantedBy=multi-user.target

Enable and start it:

Terminal
sudo systemctl daemon-reload
sudo systemctl enable --now fivem
sudo systemctl status fivem
journalctl -u fivem -f      # follow the console output

txAdmin still restarts FXServer itself when it crashes. systemd restarts txAdmin if the whole process dies, and starts everything on boot. In txAdmin Settings > FXServer, enable starting the server when txAdmin starts, so a reboot brings the game server back without you logging in.

Note

With systemd you do not have an interactive console. Use txAdmin’s Live Console page to type server commands.

7. MariaDB (for frameworks)

Terminal
sudo apt install -y mariadb-server
sudo mariadb-secure-installation

Then open the MariaDB shell with sudo mariadb and create a database user for FiveM instead of using root:

SQL
CREATE USER 'fivem'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON *.* TO 'fivem'@'localhost';
FLUSH PRIVILEGES;
EXIT;

GRANT ALL ON *.* lets the txAdmin deployer create the database for you. After deploying you can tighten it to the one database (GRANT ALL ON yourdb.* ...). Keep MariaDB bound to 127.0.0.1 (the default on Debian and Ubuntu) and never open port 3306 in the firewall. More in Database setup.

Linux gotchas

  • File names are case sensitive. ensure qb-Core will not find qb-core. Stream files referenced in metas must match their exact case too.
  • Line endings. Scripts edited on Windows work fine, but shell scripts (.sh) with Windows line endings fail with bad interpreter. Convert with sed -i 's/\r$//' script.sh.
  • Permissions. If you upload files as root (for example with SFTP as root), the fivem user cannot read them. Fix with sudo chown -R fivem:fivem /home/fivem/server.
  • Paths with spaces or brackets. Quote them in the shell: cd "resources/[local]".

The vanilla way (no txAdmin)

From the official guide:

Terminal
git clone https://github.com/citizenfx/cfx-server-data.git ~/server-data
cd ~/server-data
nano server.cfg   # same content as the Windows vanilla example
bash ~/server/run.sh +exec server.cfg

You must start it from inside the data folder, with +exec server.cfg. See the Windows guide for a minimal server.cfg.

Updating later

Stop the server, move the old alpine folder and run.sh aside, extract the new fx.tar.xz in the same place, start again. Your txData is untouched. The full routine, including rollback, is in Updating artifacts safely.