Self-host n8n | Complete Guide For Beginners

EatTheBlocksAbout 5 min readJun 25, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

Self-hosting N8N, VPS (Virtual Private Server), Docker, Docker Compose, npm packages, SSH, Digital Ocean, Subdomain, DNS, Caddy, Environment Variables, Docker Volumes, N8N Instance Management (Upgrades, Troubleshooting).

Self-Hosting N8N: An Overview

The video explains how to self-host N8N, an open-source workflow automation platform, as an alternative to using N8N's hosted service. Self-hosting offers cost savings, better data control, improved privacy, and customization options like installing custom npm packages.

Why Self-Host N8N?

  • Cost Savings: Self-hosting eliminates monthly subscription fees associated with the hosted N8N service. While a VPS incurs costs, it's generally cheaper, especially for multiple instances.
  • Data Control: Self-hosting gives you complete control over your data, preventing account shutdowns and enhancing privacy, crucial for sensitive industries like healthcare.
  • Customization: Self-hosting allows installing any npm package, expanding workflow capabilities.

Hosting N8N on Your Laptop (Local Installation)

This method is suitable for simple workflows and avoids VPS costs.

Step-by-Step Process:

  1. Install Docker: Download and install Docker Desktop from the official Docker website.
  2. Download N8N Docker Image: Open a terminal and run docker pull n8nio/n8n.
  3. Run N8N Container: Execute docker run -d -p 5678:5678 --name n8n n8nio/n8n. The -d flag runs the container in detached mode, -p maps port 5678, and --name assigns a name to the container.
  4. Access N8N: Open a web browser and navigate to http://localhost:5678.
  5. Create Admin Account: Follow the on-screen instructions to create an admin account.
  6. Stop N8N: Press Ctrl+C in the terminal to stop the container.

Downsides of Local Installation:

  • OAUTH Issues: Difficulties with OAUTH-based APIs (e.g., Google APIs) due to the inability to receive requests from the internet. N8N's tunnel service is mentioned as a potential but unreliable workaround.
  • Uptime Limitations: Workflows cannot run 24/7 as the laptop needs to be constantly running.

Hosting N8N on a VPS (Virtual Private Server)

A VPS provides a server that runs 24/7, suitable for professional use. Digital Ocean is recommended for beginners due to its pre-built N8N droplets.

Using Digital Ocean's Pre-Built N8N Droplet:

  1. Create a Digital Ocean Account: Sign up on the Digital Ocean website.
  2. Create a Droplet: In the dashboard, go to the "Droplets" menu and click "Create Droplet."
  3. Choose N8N Droplet: In the "Choose an image" section, go to the "Marketplace" tab and select the N8N droplet. Note that this is a third-party image.
  4. Select Plan: Choose a CPU, memory, and storage package. Start with the lowest package and upgrade later if needed.
  5. Authentication: Choose SSH keys for secure connection. Follow the instructions to generate and add your SSH public key.
  6. Create Droplet: Click "Create Droplet."
  7. Configure DNS: Point a subdomain to the droplet's IP address by adding an A record in your DNS editor.
  8. Connect via SSH: Use the command ssh root@your_droplet_ip to connect to the droplet.
  9. Initial Setup: Follow the on-screen instructions to configure the subdomain and domain name.
  10. Access N8N: Access N8N in your browser using the configured subdomain and create your admin account.

Installing N8N on a VPS with Ubuntu (Manual Installation)

This method offers more flexibility and allows using any hosting provider.

Step-by-Step Process:

  1. Create a Digital Ocean Droplet: Choose Ubuntu as the operating system and select a basic shared CPU plan.
  2. Connect via SSH: Use the command ssh root@your_droplet_ip to connect to the droplet.
  3. Create a New User: Create a new user (e.g., "n8n") using adduser n8n and grant sudo privileges using usermod -aG sudo n8n.
  4. Switch to the New User: Switch to the new user's home directory using sudo su - n8n.
  5. Clone N8N Setup Repository: Clone the N8N setup repository using git clone https://github.com/n8n-io/n8n-docker.git.
  6. Navigate to the Directory: cd n8n-docker
  7. Install Docker: Follow the official Docker installation instructions for Ubuntu.
  8. Create Docker Volumes: Create Docker volumes for Caddy and N8N data using docker volume create n8n_caddy_data and docker volume create n8n_data.
  9. Configure DNS: Point a subdomain to the droplet's IP address by adding an A record in your DNS editor.
  10. Configure Environment Variables: Edit the .env file using a text editor (e.g., vim .env) to customize the data folder, domain name, and subdomain.
  11. Configure Caddy: Edit the Caddyfile in the caddy/config folder to replace the placeholder with your subdomain.
  12. Start Docker Compose: Start the N8N instance using docker-compose up -d.
  13. Access N8N: Access N8N in your browser using the configured subdomain and create your admin account.

Managing Your N8N Instance

Troubleshooting:

  • If N8N crashes, Docker should restart it automatically.
  • If the issue persists, SSH into the server, stop the container using docker stop n8n, and restart it using docker start n8n.

Upgrading N8N:

  1. Check for new version message in the N8N menu bar.
  2. Download the latest N8N Docker image.
  3. Stop the container.
  4. Restart the container.

Installing Custom npm Packages:

  1. SSH into the server and stop the N8N instance.

  2. Create a Dockerfile with the following structure:

    FROM n8nio/n8n
    USER root
    RUN npm install cheerio  # Replace cheerio with your desired package(s)
    USER node
    

    If you want to install multiple packages:

    FROM n8nio/n8n
    USER root
    RUN npm install cheerio request
    USER node
    
  3. Modify the docker-compose.yml file to use the custom Dockerfile:

    version: "3.7"
    services:
      n8n:
        build:
          context: .
          dockerfile: Dockerfile
        image: n8n-custom # Local name for the container
        restart: always
        ports:
          - "5678:5678"
        environment:
          - NODE_ENV=production
          - N8N_BASIC_AUTH_ACTIVE=true
          - N8N_BASIC_AUTH_USER
          - N8N_BASIC_AUTH_PASSWORD
          - NODE_FUNCTION_ALLOW_EXTERNAL=cheerio # Add the package name here
        volumes:
          - n8n_data:/home/node/.n8n
    
  4. Add the NODE_FUNCTION_ALLOW_EXTERNAL variable to the .env file, listing the npm packages separated by commas (e.g., NODE_FUNCTION_ALLOW_EXTERNAL=cheerio,request).

  5. Restart the N8N instance using docker-compose up -d.

Conclusion

Self-hosting N8N provides significant advantages in terms of cost, data control, and customization. The video details the steps for installing N8N both locally using Docker and on a VPS, with a focus on Digital Ocean. It also covers essential management tasks like troubleshooting, upgrading, and installing custom npm packages, empowering users to leverage the full potential of N8N for their automation needs. The speaker also promotes his AI automation agency, encouraging business owners to inquire about AI and automation solutions.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.