How to Install n8n on a Raspberry Pi: A Step-by-Step Guide

Raspberry Pi is a versatile, compact computer perfect for home automation, personal projects, and running various applications. One such application is n8n, a popular open-source workflow automation tool. With n8n, you can automate repetitive tasks by integrating different services without needing complex coding.

In this guide, we will walk through the installation of n8n on a Raspberry Pi, and explore two methods of running it as a background service: via systemd and PM2. I will also share why this setup can be particularly useful for background jobs with databases like Supabase.

Why Use n8n on Raspberry Pi?

If you're working with tools like Supabase (an open-source Firebase alternative), n8n can be a powerful companion for automating background tasks. For instance, n8n can monitor your Supabase database for changes and trigger workflows based on real-time updates. Running n8n on a Raspberry Pi allows you to automate processes locally, without the need for cloud services, making it an efficient and cost-effective solution for managing background jobs on your Supabase DB.

Prerequisites

Before we start, ensure you have the following:

  • A Raspberry Pi 3 or newer (preferably with Raspberry Pi OS installed).
  • A microSD card (8GB or larger recommended).
  • A stable Internet connection.
  • Basic knowledge of using the terminal.
  • An active SSH connection or direct access to the Raspberry Pi.

Step 1: Update Your Raspberry Pi

Before installing any software, it’s a good idea to update your system to the latest packages.

Open a terminal and run:

sudo apt update && sudo apt upgrade -y

This ensures your Raspberry Pi has the most up-to-date software and dependencies.

Step 2: Install Node.js and npm

n8n is built with Node.js, so you need to install Node.js and npm (Node's package manager) on your Raspberry Pi.

Install Node.js

Run the following command to install Node.js version 18 (which is compatible with n8n):

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs

Verify the installation:

node -v
npm -v

You should see the versions of Node.js and npm installed.

Step 3: Install n8n

Now that Node.js and npm are installed, install n8n using npm:

sudo npm install -g n8n

This will globally install n8n, making it accessible from anywhere in the terminal.

Step 4: Set Up n8n as a Service Using Systemd

For convenience, you can run n8n automatically as a service, so it starts every time the Raspberry Pi boots up.

  1. Create a new systemd service file:

    sudo nano /etc/systemd/system/n8n.service
    
  2. Add the following content:

    [Unit]
    Description=n8n Automation Tool
    After=network.target
    
    [Service]
    ExecStart=/usr/bin/n8n
    Restart=always
    User=pi
    Environment=PATH=/usr/bin:/usr/local/bin
    Environment=NODE_ENV=production
    WorkingDirectory=/home/pi/
    
    [Install]
    WantedBy=multi-user.target
    

    Adjust the ExecStart, User, and WorkingDirectory as needed.

  3. Enable and start the service:

    sudo systemctl enable n8n
    sudo systemctl start n8n
    
  4. Check the status to ensure it's running:

    sudo systemctl status n8n
    

Step 4 (Alternative): Use PM2 to Manage n8n

PM2 is a popular process manager for Node.js that can be used as an alternative to systemd. It offers additional features like real-time logs, automatic restarts, and easier monitoring.

Install PM2

First, install PM2 globally:

sudo npm install -g pm2

Start n8n with PM2

Start n8n with PM2 using:

pm2 start n8n

Check the status of n8n with:

pm2 list

Ensure n8n Starts on Boot

To make sure n8n starts automatically on boot:

  1. Save the PM2 process list:

    pm2 save
    
  2. Set up PM2 to start on boot:

    pm2 startup
    

Follow the on-screen instructions to finish the setup.

Monitoring n8n with PM2

You can view n8n logs in real-time with:

pm2 logs n8n

Step 5: Access the n8n Web Interface

By default, n8n runs on port 5678. You can access the n8n web interface by opening your browser and navigating to:

http://<your-raspberry-pi-ip>:5678

To find your Raspberry Pi's IP address, run:

hostname -I

Step 6: Configure Local Network Access

If you’re running n8n on your local network and don’t need authentication, set the following environment variable to disable basic authentication:

N8N_BASIC_AUTH_ACTIVE=false

When using PM2, this can be set with:

pm2 start n8n --env N8N_BASIC_AUTH_ACTIVE=false

If using the systemd method, add the line to the n8n.service file under the Environment section:

Environment=N8N_BASIC_AUTH_ACTIVE=false

After making the changes, restart the service:

sudo systemctl restart n8n

This setup will make it easier to access n8n from within your local network without login credentials.

Step 7: Start Automating with Supabase

Now that n8n is up and running, you can begin integrating it with your Supabase database. You can use n8n’s built-in triggers to monitor your Supabase instance for changes and perform actions like sending notifications, updating other databases, or interacting with external APIs.

For example, you could:

  • Monitor your Supabase database for new entries and trigger workflows.
  • Automate backups of your Supabase data.
  • Send notifications when specific conditions are met within your database.

By running n8n as a background job on your Raspberry Pi, you have a powerful and efficient way to manage automations without relying on cloud services.

Conclusion

Running n8n on a Raspberry Pi allows you to automate background jobs for services like Supabase directly from your local environment. Whether you use systemd or PM2, this setup ensures that n8n runs smoothly and reliably as a background service. With this flexible tool, you can streamline your tasks and improve the efficiency of your database operations.

Happy automating!

Do you have any questions or issues setting up n8n on your Raspberry Pi? Drop me a message on X.