Blog

Discourse requires at least 2GB of swap

Discourse

Tutorial: Setting up Swap for Discourse on Ubuntu 22.04 LTS

Discourse is a highly recommended platform for building communities. In this tutorial, you will learn how to resolve the swapfile issue when setting up Discourse on a fresh Ubuntu 22.04 LTS server.

Prerequisites

  • A fresh Ubuntu 22.04 LTS server
  • Root access or a user with sudo privileges

Step 1: Running Discourse Setup

  1. Access your Ubuntu server, either directly or through SSH.
  2. Open a terminal or SSH session.
  3. Change to the /var/discourse directory using the following command:
cd /var/discourse
  1. Start the Discourse setup process by running the following command:
./discourse-setup

Step 2: Identifying the Swapfile Issue

When running the Discourse setup command, you may encounter the following warning message:

WARNING: Discourse requires at least 2GB of swap when running with 2GB of RAM or less. This system does not appear to have sufficient swap space.

Without sufficient swap space, your site may not work properly, and future upgrades of Discourse may not complete successfully.

Ctrl+C to exit or wait 5 seconds to have a 2GB swapfile created.

If you see this message, it means that your server does not have sufficient swap space.

Step 3: Troubleshooting the Swapfile Issue

  1. The following error messages may appear during the Discourse setup process:
install: cannot remove '/swapfile': Operation not permitted
fallocate: fallocate failed: Text file busy
mkswap: error: /swapfile is mounted; will not make swapspace
swapon: /swapfile: swapon failed: Device or resource busy
/swapfile       swap    swap    auto      0       0
vm.swappiness = 10
Failed to create swap: are you root? Are you running on real hardware, or a fully virtualized server?
  1. If you are running the discourse-setup command as root or using sudo, the problem may be that you already have a swap file that is in use. To resolve this issue, you need to disable the existing swap file.

Step 4: Disabling the Swap File

  1. To disable the swap file, run the following command:
sudo swapoff -a
  1. After disabling the swap file, you can now rerun the discourse-setup command to resolve the swapfile issue.

Step 5: Running Discourse Setup Again

  1. Run the discourse-setup command again:
./discourse-setup
  1. The swapfile issue should now be resolved, and you can proceed with the Discourse setup process.

Congratulations! You have successfully resolved the swapfile issue when setting up Discourse on your Ubuntu 22.04 LTS server. You can now proceed with the Discourse installation and configuration as needed.

Note: It is recommended to ensure that your server meets the minimum requirements, including sufficient swap space, for optimal performance of Discourse.