Tag: Raspberry pi

  • Installing n8n on Raspberry Pi 3B

    Installing n8n on Raspberry Pi 3B

    I recently decided to set up n8n on my Raspberry Pi 3B to automate my social media workflow, thanks to n8n’s availability for self hosted setups.

    The Pi was already running Pi-hole 24/7 as my network’s DNS server, so I wanted a solution that wouldn’t interfere with it. Here’s what I learned after trying the standard approach and eventually succeeding with Docker.

    The Failed Attempt: Direct Install

    I started with a guide designed for newer Raspberry Pis (Pi 4/5), following instructions from various tutorials that suggested a direct npm installation. The process seemed straightforward:

    bash

    # The approach that DIDN'T work on Pi 3B
    npm install n8n -g
    n8n start
    

    What went wrong: The installation would start, but then freeze the entire Pi. The limited 1GB RAM on the Pi 3B couldn’t handle the build process. I had to force restart the Pi multiple times. Even the uninstall and update commands wouldn’t work properly, leaving me to manually remove the n8n folder.

    The Solution: Docker Installation

    After the npm failures, I switched to Docker following instructions provided by Claude. This approach uses pre-built images, completely bypassing the resource-intensive build process. Here’s the complete setup that worked perfectly.

    Step 1: Install Docker

    bash

    # Install Docker
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    
    # Add your user to docker group (avoids needing sudo)
    sudo usermod -aG docker $USER
    
    # Log out and back in for group changes to take effect
    

    Verify Docker is installed:

    bash

    docker --version
    

    Step 2: Install Docker Compose

    bash

    sudo apt-get update
    sudo apt-get install -y docker-compose
    

    Step 3: Create n8n Directory and Configuration

    bash

    # Create directory for n8n
    mkdir -p ~/n8n
    cd ~/n8n
    
    # Create docker-compose.yml
    cat > docker-compose.yml << 'EOF'
    version: '3.3'
    
    services:
      n8n:
        image: n8nio/n8n:latest
        container_name: n8n
        restart: unless-stopped
        ports:
          - "5678:5678"
        environment:
          - N8N_SECURE_COOKIE=false
        volumes:
          - ./data:/home/node/.n8n
    EOF
    

    Note on version: I initially used version: '3.8' but got an error about unsupported version. The older docker-compose on Pi 3B required version: '3.3'.

    Step 4: Fix Permissions (Critical!)

    bash

    # Create data directory and set proper permissions
    mkdir -p ~/n8n/data
    sudo chown -R 1000:1000 ./data
    

    This step is crucial. n8n runs as user ID 1000 inside the container and needs write access to save workflows, credentials, and configuration files.

    Step 5: Start n8n

    bash

    docker-compose up -d
    

    Check if it’s running:

    bash

    docker-compose ps
    docker-compose logs -f n8n
    

    The startup takes 30-60 seconds on a Pi 3B. Once you see logs indicating n8n is running, you can access it at http://[your-pi-ip]:5678 from any device on your network.

    Press Ctrl+C to exit the logs view (this doesn’t stop n8n, just stops viewing the logs).

    Key Configuration Choices

    Why N8N_SECURE_COOKIE=false?

    By default, n8n requires HTTPS for secure cookies. Since we’re running locally without SSL, this setting allows access from other devices on your network. This is perfectly safe for a home network setup.

    Why restart: unless-stopped?

    This ensures n8n automatically starts when your Pi reboots. Docker is configured to start on boot by default, and it will automatically restart any containers marked with this policy.

    Coexisting with Pi-hole

    The beauty of this setup is that n8n and Pi-hole run completely independently:

    • Pi-hole typically runs on port 53 (DNS) and 80/443 (web interface)
    • n8n runs on port 5678
    • Both use Docker’s default network, with no conflicts
    • Combined RAM usage is manageable on the Pi 3B

    Managing n8n

    Here are the essential commands (run from ~/n8n directory):

    bash

    # Stop n8n
    docker-compose stop
    
    # Start n8n
    docker-compose start
    
    # Restart n8n (useful after config changes)
    docker-compose restart
    
    # View logs
    docker-compose logs -f n8n
    
    # Update n8n to latest version
    docker-compose pull
    docker-compose up -d
    
    # Complete removal
    docker-compose down
    rm -rf ~/n8n
    

    Handling OAuth Credentials

    One challenge I encountered was setting up OAuth credentials (Google, LinkedIn, etc.) when accessing the local n8n from my MacBook. Many OAuth providers require the redirect URL to be either HTTPS or localhost.

    Solution: SSH Tunnel

    bash

    # On your Mac/laptop, create an SSH tunnel
    ssh -L 5678:localhost:5678 pi@[your-pi-ip]
    
    # Then access n8n at http://localhost:5678 in your browser
    

    This makes your browser think n8n is running locally, which satisfies OAuth requirements. Once credentials are saved, you can close the tunnel and access n8n normally via the Pi’s IP address. You only need the tunnel when initially setting up OAuth credentials.

    Performance Notes

    The Pi 3B handles n8n surprisingly well for automation workflows:

    • Startup time: 30-60 seconds after reboot
    • Workflow execution: Perfectly adequate for scheduled tasks
    • Web interface: Responsive enough for editing workflows
    • RAM usage: n8n + Pi-hole combined use ~45%, leaving headroom

    For workflows that need AI processing (like my LinkedIn post generator), I’m calling LM Studio running on my MacBook over the network. The Pi handles the orchestration, while the heavy AI work happens on more powerful hardware.

    Troubleshooting Tips

    If the container keeps restarting: Check permissions on the data folder. The error logs will show “EACCES: permission denied” if this is the issue.

    If you can’t access from other devices: Make sure you’ve set N8N_SECURE_COOKIE=false in the environment variables and restarted the container.

    If Docker isn’t starting on boot: Enable it with sudo systemctl enable docker

    Final Thoughts

    The Docker approach transformed what seemed like an impossible task into a straightforward 10-minute setup. While the Pi 3B isn’t powerful enough to compile n8n from source, it’s more than capable of running the pre-built Docker image alongside Pi-hole.

    If you’re running a Pi 3B and want to add n8n to your home automation stack, skip the npm route entirely and go straight to Docker. Your Pi (and your sanity) will thank you.

    Complete Setup Script

    For reference, here’s the entire setup in one script:

    bash

    #!/bin/bash
    
    # Install Docker
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    sudo usermod -aG docker $USER
    
    # Install Docker Compose
    sudo apt-get update
    sudo apt-get install -y docker-compose
    
    # Create n8n directory
    mkdir -p ~/n8n
    cd ~/n8n
    
    # Create docker-compose.yml
    cat > docker-compose.yml << 'EOF'
    version: '3.3'
    
    services:
      n8n:
        image: n8nio/n8n:latest
        container_name: n8n
        restart: unless-stopped
        ports:
          - "5678:5678"
        environment:
          - N8N_SECURE_COOKIE=false
        volumes:
          - ./data:/home/node/.n8n
    EOF
    
    # Create and set permissions on data directory
    mkdir -p data
    sudo chown -R 1000:1000 ./data
    
    # Start n8n
    docker-compose up -d
    
    echo "n8n is starting up. Access it at http://$(hostname -I | awk '{print $1}'):5678 in about 60 seconds."
    echo "View logs with: docker-compose logs -f n8n"
    

    Save this as install-n8n.sh, make it executable with chmod +x install-n8n.sh, and run it with ./install-n8n.sh. Note that you’ll need to log out and back in after the script runs for Docker group permissions to take effect, then run docker-compose up -d from the ~/n8n directory.

  • Getting rid of ads with Pi-hole

    Getting rid of ads with Pi-hole

    I’ve been using Pi-hole running on a Raspberry Pi 3B+ for the past 2 1/2 years, and it has really spoilt me to the extent that I have forgotten what ads on web pages and mobile apps look like (the limited travel in the last couple of years has also helped). It’s pretty effective in getting rid of the pop-up mobile ads and the in page banner ads on all devices connected to the wifi.

    The setup process is quite simple if you have your own router or at least change the DNS server on the home router:

    • First off, get hold of a Raspberry Pi (even the model Zero is powerful enough for the Pi-hole), and the necessary peripherals like a case, SD card, charger & LAN cable. There are many readymade kits with the OS preinstalled sold online including Amazon, which saves a good deal of time.
    • Initial setup is easier with a monitor & keyboard + mouse attached to the Pi. Once this is done you can connect it to your router using a LAN cable and access it through a Telnet client/mobile app like Putty on any of your devices in the home network.
    • Next, you need to install Pi-hole on the Pi (you can do it during the setup itself), and configure the router to use the Pi as your DNS server. If you are stuck without admin access to your router, then you may need to configure each device to use the Pi separately.
    • You can also install mobile apps to manage the Raspberry & Pi-hole quite easily through your phone. There are multiple apps available for both Android & iOS.

    Once everything is setup, you should have an ad free experience on your devices (not all ads can be blocked of course). I’ve found about 10-15% of the queries on my home network getting blocked, and this includes devices like Android & iPhones, iPads, Android TV, Amazon Echo, Homepods & Windows laptops of course.