Linux Commands and Scripts

How to Install a FiveM Server on Ubuntu 20.04

In this tutorial, we will see how to install a FiveM server on Ubuntu 20.04.

Prerequisites

1. Keep your server up to date

Always keep your server up to date for security updates.

# apt update -y

# apt- upgrade -y

2. Add ports in UFW

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

# ufw allow 30120
# ufw allow 30110

3. Install FiveM

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

# mkdir ~/fivem_server
# cd ~/fivem_server

Download the latest master branch using following command:

# wget https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/3074-0c5d71ad77873c159d7542a7e8314d9696c1b55b/fx.tar.xz

For latest master branch build visit the artifacts server. Download it by wget command.

After download, extract it using 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 directory outside the server files folder. This directory will contain the server resources. The command below will clone the repository to a new folder called fivem_resources in your home directory.

Now, generate a free license in FiveM license key,

We will create one configuration file with the name of server.cfg in fivem_resources directory.

# vi ~/fivem_resources/server.cfg

and add following lines:

# 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 (96×96 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

Note: relace this replaceThisWithYourLicenseKey with your generated license key. You can also change some of the settings if you want to.

Once done, save and exit.

4. Start 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

Optional: Run the server in the background

To run the server in the background, use screen session.

# 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.

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.

We have successfully installed FiveM server.

In this tutorial, we have seen how to install a FiveM server on Ubuntu 20.04.

Related Articles