Installing a FiveM server on Linux

A full FiveM install on a fresh Debian or Ubuntu server: artifacts, server data, a keymaster key, txAdmin, and a systemd unit.

Game servers6 min read

On this page
  1. Before you start
  2. Install
  3. Checking it worked
  4. Running without txAdmin
  5. Related

This is a complete install on a blank Debian or Ubuntu server, from a fresh SSH session to a FiveM server that survives a reboot. It takes about fifteen minutes of typing, and the only thing you have to leave the terminal for is the licence key.

The commands below are for Debian 11 or newer and Ubuntu 20.04 or newer. If you have not connected to the machine yet, start with Connecting to your server.

Before you start

You need three things: root access to the server, its public IPv4 address, and a Cfx.re account, which is the same account you use for the FiveM client. If you do not already have a database in mind, install one later; the base server does not need it.

The layout this guide builds:

/home/fivem/
├── artifacts/      the FXServer build: run.sh, alpine/
├── server-data/    resources/, server.cfg, your own scripts
└── txData/         created by txAdmin on first run

Keeping the build and your data in separate directories is what makes an artifact update a folder swap rather than a merge. See Updating FiveM artifacts.

Install

  1. Update the system and install the prerequisites

    As root:

    Shell
    apt update && apt upgrade -y
    apt install -y curl xz-utils git tmux ca-certificates

    xz-utils unpacks the artifact archive, git fetches the default server data, and tmux is the fallback if you decide not to use systemd. The artifacts bring their own runtime, so there is no Node, .NET, or Mono to install.

  2. Create a user for the server

    Shell
    adduser --disabled-password --gecos "" fivem

    That creates /home/fivem with no password login. Switch to it whenever you work on the server:

    Shell
    su - fivem

    Everything in steps 3 to 7 runs as fivem. The systemd unit in step 8 is written as root but runs the server as fivem.

  3. Fetch the artifacts

    Open https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/ in a browser. Each row is a build, and one is marked as the recommended build. Copy its link, which ends in fx.tar.xz.

    Then, as fivem:

    Shell
    mkdir -p ~/artifacts
    cd ~/artifacts
    curl -sSL -o fx.tar.xz "PASTE_THE_LINK_HERE"
    tar xf fx.tar.xz
    rm fx.tar.xz
    chmod +x run.sh

    You should now have run.sh and an alpine directory. Take the recommended build rather than the newest one unless you have a specific reason; Updating FiveM artifacts covers the difference.

  4. Get the server data files

    The artifacts contain the server, not a gamemode. Cfx.re publishes a starting set of resources:

    Shell
    git clone https://github.com/citizenfx/cfx-server-data.git ~/server-data

    That gives you ~/server-data/resources/ with the default resources, and no server.cfg. You write that yourself in step 6, or let txAdmin write one for you in step 7.

  5. Create a licence key in keymaster

    Sign in at https://keymaster.fivem.net with your Cfx.re account and create a new server key. It asks for a label, so name it after this server, and for the server's IP address, which is the public IPv4 address of this machine.

    Copy the key somewhere safe. If the server later moves to a different address, edit the existing key in keymaster rather than creating a second one.

  6. Open the ports

    The server needs TCP and UDP 30120 reachable from the internet. On Clouduxe that is the Firewall tab: apply the FiveM (GTA RP) preset, which opens both in one step, or add the two rules yourself. See Game presets and Port rules.

    If you have also enabled a firewall on the machine itself, open the ports there too. Check whether one is running:

    Shell
    ufw status
    nft list ruleset

    On a stock Debian or Ubuntu image both usually come back empty, in which case there is nothing to do on the host.

    Leave TCP 40120 closed to the internet. Step 7 reaches txAdmin over an SSH tunnel instead.

  7. Start txAdmin and run the setup

    From a fixed working directory, so txAdmin's txData folder always lands in the same place:

    Shell
    cd ~
    ~/artifacts/run.sh

    txAdmin starts and prints a URL and a one-time PIN. The PIN expires after a few minutes; if you miss it, stop the process with Ctrl-C and start it again.

    Rather than exposing port 40120, tunnel it over SSH. From your own computer, in a second terminal:

    Shell
    ssh -L 40120:127.0.0.1:40120 root@203.0.113.10

    Leave that running and open http://127.0.0.1:40120 in your browser. Enter the PIN, create your admin account with a strong password, then work through the setup: choose the option for an existing server data folder, give it /home/fivem/server-data, and paste the licence key from step 5. txAdmin writes a server.cfg if there is not one already.

  8. Keep it running

    The server should start on boot and restart if it crashes. As root, create /etc/systemd/system/fivem.service:

    Config
    [Unit]
    Description=FiveM server (txAdmin)
    After=network-online.target
    Wants=network-online.target
     
    [Service]
    Type=simple
    User=fivem
    Group=fivem
    WorkingDirectory=/home/fivem
    ExecStart=/home/fivem/artifacts/run.sh
    Restart=on-failure
    RestartSec=10
     
    [Install]
    WantedBy=multi-user.target

    Then:

    Shell
    systemctl daemon-reload
    systemctl enable --now fivem
    systemctl status fivem
    journalctl -u fivem -f

    WorkingDirectory matters. txAdmin keeps its own data beside the directory it is started from, so pinning it here means systemd and a manual run always find the same profile.

    Under this unit, systemd supervises txAdmin and txAdmin supervises the game server. Restarting from the txAdmin interface restarts the game server only; systemctl restart fivem restarts both.

systemd: fivem.serviceStarts on boot, restarts on failure, runseverything as the fivem usertxAdminTCP 40120The web admin panel. Starts, stops andrestarts the game server.Game serverUDP and TCP 30120FXServer, with the resources andserver.cfg in /home/fivem/server-dataWhat a restart restartsRestart in txAdminGame serversystemctl restart fivemtxAdminGame server
What the install leaves running, one inside the other. systemd keeps txAdmin up and txAdmin keeps the game server up, so a restart from txAdmin restarts only the game server, while systemctl restart fivem restarts both. Illustration.

Checking it worked

The console, in journalctl -u fivem -f or in txAdmin, tells you most of it. Look for the line confirming licence key authentication, then for each resource starting. A resource that fails to start says so on its own line, with the reason.

From another machine, confirm the TCP endpoint is reachable from outside:

Shell
curl -s http://203.0.113.10:30120/info.json

A JSON reply means the port is open and the server is answering. A timeout means the port is closed somewhere between you and the server, and the server list is as stuck as you are. Nothing on the game port answers to a browser, so this is the honest test.

If that works and players still cannot join, work through When players cannot connect.

Running without txAdmin

You do not have to use txAdmin. Pass a config file and you get a plain server console instead:

Shell
cd ~/server-data
~/artifacts/run.sh +exec server.cfg

If you go this route, run it inside tmux so closing your SSH session does not kill the server:

Shell
tmux new -s fivem
cd ~/server-data && ~/artifacts/run.sh +exec server.cfg

Detach with Ctrl-b then d, and come back with tmux attach -t fivem. A tmux session does not survive a reboot, so for anything you care about, use the systemd unit and change its ExecStart to the command above.

Need a server, or a hand with one?

Pick a plan to deploy a server, or open a ticket in the panel. Support runs 24/7/365.