Run This Ai
EN DE

How to Install n8n on Ubuntu 24.04

Complete step-by-step guide to install n8n on Ubuntu 24.04 with Docker Compose, Nginx reverse proxy with SSL, environment variables reference, automatic backups, and troubleshooting.

n8n Logo

Why Install n8n on Ubuntu?

n8n is one of the most powerful open-source workflow automation platforms out there β€” think of it as a self-hosted Zapier that gives you full control over your data, infrastructure, and costs. With native AI/LLM nodes, you can build agentic workflows that connect your entire tech stack.

Running it on Ubuntu 24.04 is the sweet spot: you get the long-term support of a stable OS, Docker's portability, and full ownership of your automation data. No per-execution fees, no rate limits, no vendor lock-in.

Prerequisites

  • Ubuntu 24.04 server (LTS)
  • At least 2 CPU cores, 4GB RAM (8GB recommended for heavy workflows)
  • 20GB+ free disk space
  • Docker and Docker Compose installed
  • Port 5678 available (n8n default)
  • A domain name pointing to your server (recommended for HTTPS)

Step 1: Install Docker (if not already installed)

Ubuntu 24.04 makes Docker installation straightforward. Run these commands:

# Update system
sudo apt update && sudo apt upgrade -y

# Install Docker prerequisites
sudo apt install -y ca-certificates curl gnupg lsb-release

# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Add Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

# Verify installation
sudo docker --version
sudo docker compose version

Add your user to the docker group to run Docker without sudo:

sudo usermod -aG docker $USER
# Log out and back in for this to take effect

Step 2: Deploy n8n with Docker Compose

Create a directory and a docker-compose.yml file. This is the most maintainable way to run n8n in production:

mkdir -p ~/n8n
cd ~/n8n
nano docker-compose.yml

Paste this configuration:

services:
  n8n:
    image: n8nio/n8n:latest
    restart: unless-stopped
    container_name: n8n
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=n8n.yourdomain.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.yourdomain.com
      - DB_TYPE=sqlite
      - DB_SQLITE_DATABASE=/home/node/.n8n/database.sqlite
      - N8N_ENCRYPTION_KEY=your-strong-encryption-key-here
      - N8N_METRICS=true
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=168
    volumes:
      - ./n8n_data:/home/node/.n8n
      - ./local_files:/files

πŸ” Important: Replace your-strong-encryption-key-here with a random 32-character string. This key encrypts your credentials in the database β€” lose it and you lose access to all connected services.

Start n8n:

docker compose up -d

Check if it's running:

docker compose logs -f    # Watch startup logs
docker compose ps          # Should show "Up" status

Your n8n instance is now live at http://YOUR_SERVER_IP:5678.

Step 3: Set Up Nginx as a Reverse Proxy (for HTTPS)

Exposing n8n directly on port 5678 works for testing, but for production you need HTTPS. Here's the Nginx configuration:

sudo apt install -y nginx certbot python3-certbot-nginx

sudo nano /etc/nginx/sites-available/n8n

Add this configuration:

server {
    listen 80;
    server_name n8n.yourdomain.com;

    location / {
        proxy_pass http://localhost:5678;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_buffering off;
    }
}

Enable the site and get an SSL certificate:

sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

# Get Let's Encrypt SSL certificate
sudo certbot --nginx -d n8n.yourdomain.com

That's it β€” your n8n instance is now accessible securely at https://n8n.yourdomain.com.

Step 4: Configure Environment Variables

n8n has dozens of configuration options. Here are the most important ones for production:

VariablePurposeExample
N8N_ENCRYPTION_KEYEncrypts stored credentials32-char random string
N8N_METRICSEnables Prometheus metrics endpointtrue
EXECUTIONS_DATA_PRUNEAuto-delete old execution datatrue
EXECUTIONS_DATA_MAX_AGEKeep execution history (hours)168 (7 days)
N8N_PAYLOAD_SIZE_MAXMax webhook payload (MB)16
N8N_METRICS_INCLUDE_DEFAULT_METRICSInclude default metricstrue

Step 5: Automatic Backups

Your n8n data (workflows, credentials, execution history) is stored in the ./n8n_data directory. Set up a cron job for daily backups:

# Create backup script
sudo nano /usr/local/bin/backup-n8n.sh
#!/bin/bash
BACKUP_DIR="/backups/n8n"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR

# Stop n8n briefly for a consistent backup
docker stop n8n

# Backup the data
tar -czf "$BACKUP_DIR/n8n_backup_$TIMESTAMP.tar.gz" -C ~/n8n n8n_data/

# Restart n8n
docker start n8n

# Keep only the last 30 backups
ls -t $BACKUP_DIR/*.tar.gz | tail -n +31 | xargs -r rm

echo "Backup saved: n8n_backup_$TIMESTAMP.tar.gz"
sudo chmod +x /usr/local/bin/backup-n8n.sh

# Add to crontab β€” runs daily at 3 AM
(crontab -l 2>/dev/null; echo "0 3 * * * /usr/local/bin/backup-n8n.sh") | crontab -

Step 6: Updating n8n

n8n releases updates frequently. Here's how to update safely:

cd ~/n8n

# Pull latest image
docker compose pull

# Recreate container with new image
docker compose up -d

# Verify it's running
docker compose logs -f --tail=20

Always check the n8n changelog before major version updates β€” some releases include breaking changes or database migrations that need manual steps.

Troubleshooting Common Issues

❌ Container exits immediately

Check logs with docker compose logs. The most common cause is a missing or invalid N8N_ENCRYPTION_KEY. Make sure it's at least 32 characters long.

❌ Webhooks not working

Make sure WEBHOOK_URL and N8N_HOST are set correctly in your environment. Without these, n8n generates webhook URLs with localhost which external services can't reach.

❌ 502 Bad Gateway behind Nginx

Check that the proxy_pass port matches your n8n port. The WebSocket headers (Upgrade, Connection) are essential for the n8n editor to work behind a reverse proxy.

❌ Slow workflow execution

Increase your server's RAM. n8n keeps workflows in memory during execution, and complex workflows with 100+ nodes can consume 2-4GB each.

Conclusion

Installing n8n on Ubuntu 24.04 gives you a production-ready workflow automation platform that runs entirely on your infrastructure. With Docker Compose, Nginx reverse proxy, and automatic backups, you have a setup that scales from personal automation to team workflows.

The best part? No per-execution costs, no monthly subscription tiers, no data leaving your server. Just pure workflow automation with over 400+ integrations out of the box.

#install_guide