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.
Por enquanto, esta documentação está em inglês.
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.
1. Update the system and install tools
sudo apt update && sudo apt upgrade -y
sudo apt install -y xz-utils git curl wget tmux ufwxz-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:
sudo adduser --disabled-password --gecos "" fivem
sudo -iu fivem
mkdir -p ~/server
cd ~/serverEverything below runs as fivem unless it starts with sudo.
3. Download the Linux artifact
- Open
https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/in your browser. - Pick the recommended build (check it on our Artifacts page) and copy the link to its
fx.tar.xz. - Download and extract it on the server:
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.shReplace 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:
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 statusIf 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
cd ~/server
bash run.shFXServer starts txAdmin and prints something like:
[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)
tmux new -s fivem
cd ~/server && bash run.shDetach 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:
[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.targetEnable and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now fivem
sudo systemctl status fivem
journalctl -u fivem -f # follow the console outputtxAdmin 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)
sudo apt install -y mariadb-server
sudo mariadb-secure-installationThen open the MariaDB shell with sudo mariadb and create a database user for FiveM instead of using root:
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-Corewill not findqb-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 withbad interpreter. Convert withsed -i 's/\r$//' script.sh. - Permissions. If you upload files as
root(for example with SFTP as root), thefivemuser cannot read them. Fix withsudo 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:
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.cfgYou 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.
