Complete Guide to Setting Up a Factorio Server on Ubuntu

Are you ready to automate your factory on a grand scale? This comprehensive guide will walk you through the process of setting up your own Factorio server on Ubuntu. Whether you’re playing with friends or building a larger community, we’ve got you covered.

Prerequisites

Before we begin, ensure you have:

  1. An Ubuntu server (20.04 LTS or newer recommended)
  2. Root or sudo access to your server
  3. At least 4GB of RAM (8GB recommended for larger maps)
  4. At least 5GB of free disk space
  5. A stable internet connection

Need a reliable server to host your Factorio empire? Check out Servers Guru for high-performance gaming servers at competitive prices.

Step 1: Prepare Your Ubuntu Server

Let’s start by updating your system and installing necessary packages:

sudo apt update
sudo apt upgrade -y
sudo apt install wget tar screen -y

These packages are essential for downloading, extracting, and managing your Factorio server.

Step 2: Create a Dedicated User

It’s a good practice to run your server under a dedicated user:

sudo useradd -m factorio
sudo usermod -a -G factorio $USER
sudo mkdir -p /home/factorio/server

Log out and log back in for the group changes to take effect.

Step 3: Install the Factorio Server

Now, let’s download and set up the Factorio server:

cd /home/factorio
sudo wget https://factorio.com/get-download/stable/headless/linux64 -O factorio_headless.tar.xz
sudo tar -xf factorio_headless.tar.xz --strip-components=1 -C /home/factorio/server
sudo rm factorio_headless.tar.xz
sudo chown -R factorio: /home/factorio

Step 4: Create a New Game Save

Switch to the factorio user and create a new game save:

sudo -u factorio -s
~/server/bin/x64/factorio --create ./saves/my-save.zip

If you want to use custom map settings:

~/server/bin/x64/factorio --create ./saves/my-save.zip --map-gen-settings my-map-gen-settings.json --map-settings my-map-settings.json

Step 5: Create Start and Stop Scripts

Create a start script (/home/factorio/start_server.sh):

#!/usr/bin/env bash

wget https://factorio.com/get-download/stable/headless/linux64 -O /home/factorio/factorio_headless.tar.xz
tar -xf factorio_headless.tar.xz --overwrite --strip-components=1 -C /home/factorio/server
rm -f /home/factorio/factorio_headless.tar.xz

/usr/bin/screen -dmS factorio /bin/bash -c "/home/factorio/server/bin/x64/factorio --start-server-load-latest"
/usr/bin/screen -rD factorio -X multiuser on
/usr/bin/screen -rD factorio -X acladd root

Create a stop script (/home/factorio/stop_server.sh):

#!/usr/bin/env bash
/usr/bin/screen -Rd factorio -X stuff "/quit \r"

Make both scripts executable:

sudo chmod +x /home/factorio/start_server.sh /home/factorio/stop_server.sh

Step 6: Create a Systemd Service

Create a service file (/etc/systemd/system/factorioserver.service):

[Unit]
Description=Factorio Server
Wants=network-online.target
After=network-online.target

[Service]
Type=forking
User=factorio
Group=factorio
ExecStart=/usr/bin/bash /home/factorio/start_server.sh
ExecStop=/usr/bin/bash /home/factorio/stop_server.sh
WorkingDirectory=/home/factorio/
Restart=always
TimeoutStartSec=600

[Install]
WantedBy=multi-user.target

Step 7: Enable and Start the Service

Enable the service to start on boot:

sudo systemctl enable factorioserver

Start the service:

sudo systemctl start factorioserver

Managing Your Factorio Server

  • To start the server: sudo systemctl start factorioserver
  • To stop the server: sudo systemctl stop factorioserver
  • To enable auto-start on boot: sudo systemctl enable factorioserver
  • To disable auto-start on boot: sudo systemctl disable factorioserver

Accessing the Server Console

To access the Factorio server console:

sudo screen -r factorio

To detach from the console, press Ctrl+A, then Ctrl+D.

Optimizing Your Factorio Server

For the best gaming experience, consider these tips:

  1. Allocate Sufficient Resources: Ensure your server has enough CPU and RAM. Servers Guru offers a range of high-performance options tailored for gaming.

  2. Regular Backups: Regularly backup your save files located in /home/factorio/server/saves/.

  3. Update Frequently: The start script automatically updates the server, but you can manually update by restarting the service.

  4. Monitor Performance: Use tools like htop to monitor server resource usage.

  5. Optimize Map Settings: Adjust map settings to balance between performance and gameplay experience.

Conclusion

Congratulations! You now have your own Factorio server up and running on Ubuntu. Remember, a great gaming experience starts with a reliable server. If you’re looking for top-notch performance and 24/7 support, consider hosting your Factorio server with Servers Guru.

May your factories be ever-efficient and your resources plentiful!