How To Install a FiveM Server on Ubuntu 19.04

Published on: Tue, Dec 3, 2019 at 12:40 pm EST
Game Servers Linux Guides Ubuntu

Prerequisites

  • A Linux system running Ubuntu 19.04 with at least 1 CPU core and 2 GB of memory
  • Non-root user on the system

Before we begin

To ensure your system is fully updated before proceeding with the installation, run the following commands:

sudo apt-get update
sudo apt-get upgrade

Also, make sure to open the following ports, as they are necessary for FiveM to function properly:

  • 30120 TCP & UDP
  • 30110 TCP & UDP

Ubuntu 19.04 ships with UFW as the default firewall, you can open the necessary ports if you are using UFW by executing the following commands:

sudo ufw allow 30120
sudo ufw allow 30110

Installation

First, create an empty folder and navigate to it. This folder will hold all your FiveM server files.

mkdir ~/fivem_server 
cd ~/fivem_server

Download the latest master branch build from the artifacts server. Copy the URL for the latest server version and use wget <url> to download it to the created folder. Once you've downloaded the build, extract it using the following command:

tar -xvf fx.tar.xz

This will extract all the necessary files.

Once you've successfully extracted the downloaded archive, you can now delete it.

rm fx.tar.xz

Next clone the cfx-server-data repository to a new folder outside the server files folder. This folder will contain the server resources. The command below will clone the repository to a new folder called fivem_resources in your home directory.

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

Your server is now downloaded, but not ready yet.

Generate a FiveM license key, which is completely free and used for server identification. Use your favourite text editor to make a new file called server.cfg in your fivem_resources folder:

nano ~/fivem_resources/server.cfg

Populate it with the following content:

# Only change the IP if you're using a server with multiple network interfaces, otherwise change the port only.
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"

# These resources will start by default.
ensure mapmanager
ensure chat
ensure spawnmanager
ensure sessionmanager
ensure fivem
ensure hardcap
ensure rconlog
ensure scoreboard

# This allows players to use scripthook-based plugins such as the legacy Lambda Menu.
# Set this to 1 to allow scripthook. Do note that this does _not_ guarantee players won't be able to use external plugins.
sv_scriptHookAllowed 0

# Uncomment this and set a password to enable RCON. Make sure to change the password - it should look like rcon_password "YOURPASSWORD"
#rcon_password ""

# A comma-separated list of tags for your server.
# For example:
# - sets tags "drifting, cars, racing"
# Or:
# - sets tags "roleplay, military, tanks"
sets tags "default"

# Set an optional server info and connecting banner image url.
# Size doesn't matter, any banner sized image will be fine.
#sets banner_detail "https://url.to/image.png"
#sets banner_connecting "https://url.to/image.png"

# Set your server's hostname
sv_hostname "FXServer, but unconfigured"

# Nested configs!
#exec server_internal.cfg

# Loading a server icon (96x96 PNG file)
#load_server_icon myLogo.png

# convars which can be used in scripts
set temp_convar "hey world!"

# Uncomment this line if you do not want your server to be listed in the server browser.
# Do not edit it if you *do* want your server listed.
#sv_master1 ""

# Add system admins
add_ace group.admin command allow # allow all commands
add_ace group.admin command.quit deny # but don't allow quit
add_principal identifier.steam:110000100000000 group.admin # add the admin to the group

# Hide player endpoints in external log output.
sv_endpointprivacy true

# Server player slot limit (must be between 1 and 32, unless using OneSync)
sv_maxclients 32

# License key for your server (https://keymaster.fivem.net)
sv_licenseKey replaceThisWithYourLicenseKey

This will be your server configuration file. On the last line of the configuration, there is a setting called sv_licenseKey. Change this setting to your generated license key. Also, all configuration settings in the config have comments next to them so you can understand what each setting means and change it if you want.

Once you are finished, save the file and close the editor.

Starting the server

To start the server, you need to be in the server resources directory. Then you can start the server using the runserver.sh script in the fivem_server directory. Make sure to include the +exec server.cfg parameters.

cd ~/fivem_resources && bash ~/fivem_server/run.sh +exec server.cfg

You can shutdown the server by pressing CTRL + C.

Running the server in background (optional)

To run the server in background, we'll create a new screen session for the server to run in.

cd ~/fivem_resources && screen -s "FiveM server" bash ~/fivem_server/run.sh +exec server.cfg

If you want to exit out of the FiveM console press CTRL + A, then press D. You can reopen the window again by using the command screen -r.

We can automate this by creating a bash script. Create a new file with the name of your choice and the extension .sh. Open it in your favourite text editor.

nano yourscript.sh

Then paste the following script:

#/bin/bash
cd ~/fivem_resources
screen -s "FiveM server"  bash ~/fivem_server/run.sh +exec server.cfg

Following this, mark the file as an executable by inputting the following command:

chmod +x yourscript.sh

You can now start the server by executing the script:

./yourscript.sh

Making the server start on boot (optional)

To make our server start on boot, we'll make a new Linux service that will execute the server start script. This service will be called fivem and start when your system boots up, starting the server.

Use your favorite editor to make a new file called fivem.service in /lib/systemd/system/. This will require superuser privileges.

sudo nano /lib/systemd/system/fivem.service

Populate it with the following:

[Unit]
Description=FiveM server

[Service]
Type=forking
User=username
ExecStart=/usr/bin/fivem_start.sh

[Install]
WantedBy=multi-user.target

Set your actual Linux username after User=.

Save the file and close your editor.

Create a new file /usr/bin/fivem_start.sh using your favourite text editor.

sudo nano /usr/bin/fivem_start.sh

Populate it with the following:

#!/bin/bash
screen -dm bash -c 'cd /home/username/fivem_resources && bash /home/username/fivem_server/run.sh +exec server.cfg'

Replace username with your Linux username. Save and close the file.

Mark the file as an executable by inputting the following command:

sudo chmod +x /usr/bin/fivem_start.sh

Run this command to reload the systemd manager configuration:

sudo systemctl daemon-reload

Start the service with this command:

sudo systemctl start fivem

Execute this command to make the service start on startup:

sudo systemctl enable fivem

Now you can restart your Linux server and the FiveM server will start automatically on boot. After rebooting login as the Linux account that you've installed the server as, and type the following command to open the console:

screen -r

Common Issues

  • If you don’t get any ‘resources found’, and it says ‘Failed to start resource’, you didn’t cd to the right folder.
  • If you get a lot of errors about citizen:/scripting/, you didn’t use run.sh.
  • If nothing happens at all except sending heartbeat, you didn’t use run.sh and failed to cd to the folder.
  • If no resources get started and you can’t connect, you didn’t add +exec.
  • If you get no license key was specified, one of the above applies.

Connecting to the created server

Installing the FiveM client

To connect to the server, you must own a valid Grand Theft Auto V copy and have it installed on your computer. You need to download the FiveM client installer from FiveM's official website. Run the installer and it will guide you through the installation. After you've installed the FiveM client, run it. It will ask you to login with your GTA Social Club account. Log in to your account and the installation is now complete. Proceed to the next step.

Connecting to your server

Run the installed FiveM client. If there's an update available, it'll download it automatically, just hit "accept". You'll see an option on the top called Direct Connect. Click on it and input your server's IP address into the IP:Port field. Connect to the server and you can play on it!

Want to contribute?

You could earn up to $300 by adding new articles