UbuntuUbuntu Based

How To Install n8n on Ubuntu 24.04 LTS

Install n8n on Ubuntu 24.04

n8n stands as one of the most powerful open-source workflow automation tools available today, enabling users to create sophisticated automation workflows without extensive programming knowledge. This comprehensive guide will walk you through three different methods to install n8n on Ubuntu 24.04 LTS, ensuring you can choose the approach that best fits your technical requirements and infrastructure needs.

Self-hosting n8n offers significant advantages over cloud-based alternatives. You maintain complete control over your data, avoid recurring subscription costs, and can customize the installation to meet specific security and performance requirements. Ubuntu 24.04 LTS provides an ideal foundation for hosting n8n, offering long-term support, stability, and robust security features that make it perfect for production environments.

This tutorial covers three installation methods: direct npm installation, Docker containerization, and Docker Compose deployment. Each method serves different use cases, from simple development setups to enterprise-grade production environments. Whether you’re a developer looking to automate repetitive tasks, a system administrator managing complex workflows, or an automation enthusiast exploring new possibilities, this guide provides the knowledge needed to successfully deploy n8n.

By the end of this article, you’ll have a fully functional n8n installation with proper security configurations, optimization settings, and troubleshooting knowledge to maintain your automation platform effectively.

Prerequisites and System Requirements

Hardware Requirements

Before beginning your n8n installation, ensure your Ubuntu 24.04 LTS server meets the minimum hardware specifications. For basic installations and light workloads, allocate at least 1 vCPU and 1GB of RAM. However, production environments benefit significantly from upgraded specifications.

Recommended hardware includes 2 vCPUs and 2GB of RAM for optimal performance, especially when running multiple concurrent workflows or complex automations. Storage requirements depend on your workflow complexity and data retention needs, but allocating 20GB of free disk space provides adequate room for the application, logs, and workflow data. SSD storage dramatically improves performance compared to traditional hard drives.

Network connectivity plays a crucial role in n8n functionality. Ensure stable internet connectivity for external service integrations, webhook processing, and API communications. Many n8n workflows depend on external services, making reliable network access essential for proper operation.

Software Prerequisites

Your Ubuntu 24.04 LTS server must have SSH access configured for remote administration. Root privileges or sudo access are mandatory for installation and configuration tasks. Basic command-line familiarity will significantly improve your installation experience, though this guide provides detailed step-by-step instructions for all procedures.

Consider obtaining a domain name if you plan to expose n8n externally or implement SSL/TLS encryption. While not required for local installations, domain names simplify configuration and improve security when accessing n8n remotely.

Pre-Installation System Updates

Start by updating your Ubuntu system to ensure all packages are current:

sudo apt update && sudo apt upgrade -y

Install essential packages that support various installation methods:

sudo apt install curl wget gnupg lsb-release ca-certificates software-properties-common -y

Configure UFW (Uncomplicated Firewall) for basic security:

sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 5678/tcp

Planning Your Installation Method

Choose your installation method based on specific requirements. Direct npm installation provides system-level integration and easier debugging but requires more manual dependency management. Docker installation offers containerization benefits with easier updates and isolation but requires Docker knowledge. Docker Compose provides the most flexible and production-ready approach with database integration and advanced configuration options.

Consider scalability requirements when selecting your method. Docker Compose excels in production environments requiring database integration, reverse proxy configuration, and multi-service deployments.

Method 1: Installing n8n via npm (Direct Installation)

Installing Node.js and npm

Direct npm installation requires Node.js as the runtime environment. Ubuntu 24.04 LTS repositories may not include the latest Node.js versions, so add the NodeSource repository for access to current LTS releases.

Add the NodeSource repository and GPG key:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

Install Node.js and npm:

sudo apt install nodejs -y

Verify your installation by checking versions:

node --version
npm --version

Update npm to the latest version for improved security and features:

sudo npm install -g npm@latest

Installing n8n Globally

With Node.js and npm properly configured, install n8n globally on your system:

sudo npm install -g n8n

This process downloads and installs n8n and all dependencies. Installation time varies based on internet speed and server performance, typically taking 2-5 minutes.

Test your installation by running n8n temporarily:

n8n

n8n will start and display the access URL, typically http://localhost:5678. Press Ctrl+C to stop the test run.

Creating n8n Service for Auto-Start

Production environments require n8n to start automatically and restart after failures. Create a systemd service file for proper service management:

sudo nano /etc/systemd/system/n8n.service

Add the following configuration:

[Unit]
Description=n8n - Workflow Automation Tool
After=network.target

[Service]
Type=simple
User=n8n
Group=n8n
ExecStart=/usr/local/bin/n8n
WorkingDirectory=/home/n8n
Environment=NODE_ENV=production
Environment=N8N_BASIC_AUTH_ACTIVE=true
Environment=N8N_BASIC_AUTH_USER=admin
Environment=N8N_BASIC_AUTH_PASSWORD=your_secure_password
Environment=N8N_HOST=0.0.0.0
Environment=N8N_PORT=5678
Environment=N8N_PROTOCOL=http
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Create a dedicated user for n8n:

sudo useradd -r -s /bin/false -d /home/n8n -m n8n

Set proper permissions:

sudo chown -R n8n:n8n /home/n8n

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable n8n
sudo systemctl start n8n

Check service status:

sudo systemctl status n8n

Advantages and Disadvantages

Direct npm installation offers several benefits including system-level integration, easier debugging access, and direct file system access for workflows and data. This method works well for development environments and situations requiring custom Node.js configurations.

However, drawbacks include complex dependency management, potential conflicts with other Node.js applications, and more difficult updates. System-wide changes can affect other applications, and troubleshooting requires more Node.js knowledge.

Method 2: Installing n8n using Docker

Docker Installation on Ubuntu 24.04

Docker provides containerization benefits including application isolation, easier updates, and consistent environments across different systems. Begin by installing Docker prerequisites:

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Add the Docker repository:

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

Install Docker Engine:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y

Add your user to the docker group:

sudo usermod -aG docker $USER
newgrp docker

Verify Docker installation:

docker --version
docker run hello-world

Running n8n Container

Create a directory for n8n data persistence:

mkdir -p ~/.n8n

Run n8n container with basic configuration:

docker run -d \
  --name n8n \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  -e N8N_BASIC_AUTH_ACTIVE=true \
  -e N8N_BASIC_AUTH_USER=admin \
  -e N8N_BASIC_AUTH_PASSWORD=your_secure_password \
  --restart unless-stopped \
  n8nio/n8n

This command creates a detached container with port mapping, volume mounting for data persistence, basic authentication, and automatic restart policies.

Environment Configuration

Configure additional environment variables for enhanced security and functionality:

docker run -d \
  --name n8n \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  -e N8N_BASIC_AUTH_ACTIVE=true \
  -e N8N_BASIC_AUTH_USER=admin \
  -e N8N_BASIC_AUTH_PASSWORD=your_secure_password \
  -e N8N_HOST=0.0.0.0 \
  -e N8N_PORT=5678 \
  -e N8N_PROTOCOL=http \
  -e WEBHOOK_URL=http://your-domain.com \
  -e N8N_ENCRYPTION_KEY=your_encryption_key \
  --restart unless-stopped \
  n8nio/n8n

Generate a secure encryption key:

openssl rand -base64 32

Data Persistence and Backup

Ensure data persistence by properly configuring volume mounts. Create backup procedures for your n8n data:

# Create backup
tar -czf n8n-backup-$(date +%Y%m%d).tar.gz -C ~/.n8n .

# Restore from backup
tar -xzf n8n-backup-20240101.tar.gz -C ~/.n8n

Container Management

Manage your n8n container with these essential commands:

# View container logs
docker logs n8n

# Stop container
docker stop n8n

# Start container
docker start n8n

# Restart container
docker restart n8n

# Update to latest version
docker pull n8nio/n8n
docker stop n8n
docker rm n8n
# Run new container with updated image

Monitor resource usage:

docker stats n8n

Method 3: Installing n8n with Docker Compose (Recommended)

Docker Compose Setup

Docker Compose provides the most flexible and production-ready approach for n8n deployment. Install Docker Compose if not already available:

sudo apt install docker-compose-plugin -y

Create a project directory:

mkdir ~/n8n-docker
cd ~/n8n-docker

Create a basic docker-compose.yml file:

version: '3.8'

services:
  n8n:
    image: n8nio/n8n
    container_name: n8n
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}
      - N8N_HOST=0.0.0.0
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
    volumes:
      - n8n_data:/home/node/.n8n
    restart: unless-stopped

volumes:
  n8n_data:

Advanced Docker Compose Configuration

Create an environment file for secure credential management:

nano .env

Add environment variables:

N8N_PASSWORD=your_secure_password
N8N_ENCRYPTION_KEY=your_encryption_key_here
POSTGRES_PASSWORD=your_postgres_password

Create an advanced docker-compose.yml with database integration:

version: '3.8'

services:
  postgres:
    image: postgres:15
    container_name: n8n-postgres
    environment:
      - POSTGRES_DB=n8n
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped

  n8n:
    image: n8nio/n8n
    container_name: n8n
    depends_on:
      - postgres
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}
      - N8N_HOST=0.0.0.0
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - n8n_data:/home/node/.n8n
    restart: unless-stopped

volumes:
  n8n_data:
  postgres_data:

Database Integration Options

PostgreSQL provides optimal performance for production environments. The configuration above establishes a dedicated PostgreSQL instance for n8n data storage.

For MySQL integration, modify the database service:

  mysql:
    image: mysql:8.0
    container_name: n8n-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=n8n
      - MYSQL_USER=n8n
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
    restart: unless-stopped

Update n8n environment variables accordingly:

    environment:
      - DB_TYPE=mysqldb
      - DB_MYSQLDB_HOST=mysql
      - DB_MYSQLDB_PORT=3306
      - DB_MYSQLDB_DATABASE=n8n
      - DB_MYSQLDB_USER=n8n
      - DB_MYSQLDB_PASSWORD=${MYSQL_PASSWORD}

Reverse Proxy Integration

Add Nginx reverse proxy for SSL termination and domain access:

  nginx:
    image: nginx:alpine
    container_name: n8n-nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./ssl:/etc/nginx/ssl
    depends_on:
      - n8n
    restart: unless-stopped

Create nginx.conf:

events {
    worker_connections 1024;
}

http {
    upstream n8n {
        server n8n:5678;
    }

    server {
        listen 80;
        server_name your-domain.com;
        return 301 https://$server_name$request_uri;
    }

    server {
        listen 443 ssl;
        server_name your-domain.com;

        ssl_certificate /etc/nginx/ssl/cert.pem;
        ssl_certificate_key /etc/nginx/ssl/key.pem;

        location / {
            proxy_pass http://n8n;
            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;
        }
    }
}

Production-Ready Configuration

Deploy your stack:

docker-compose up -d

Monitor services:

docker-compose ps
docker-compose logs -f n8n

Create backup procedures:

# Create backup script
cat > backup.sh << 'EOF' #!/bin/bash DATE=$(date +%Y%m%d_%H%M%S) docker-compose exec postgres pg_dump -U n8n n8n > backup_${DATE}.sql
docker run --rm -v n8n-docker_n8n_data:/data -v $(pwd):/backup ubuntu tar czf /backup/n8n_data_${DATE}.tar.gz /data
EOF

chmod +x backup.sh

Post-Installation Configuration

Initial Setup and User Account Creation

Access your n8n installation by navigating to http://localhost:5678 or your configured domain. The initial setup wizard guides you through account creation and basic configuration.

Create a strong administrator account with a complex password containing uppercase and lowercase letters, numbers, and special characters. Enable two-factor authentication if available for enhanced security.

Install n8n on Ubuntu 24.04 LTS

Authentication and Security Settings

Configure authentication settings based on your security requirements. Basic authentication provides simple username/password protection, while advanced setups may integrate with external authentication providers.

Set encryption keys for data protection:

# Generate secure encryption key
openssl rand -base64 32

Configure SSL/TLS for production environments by obtaining certificates from Let’s Encrypt or commercial certificate authorities.

Workspace Configuration

Configure default workflow settings including execution timeouts, retry policies, and error handling preferences. Set up node credentials for external service integrations, ensuring secure storage of API keys and authentication tokens.

Configure webhook settings for external integrations, including allowed origins and security headers. Set up API access tokens for programmatic control of n8n workflows.

Integration Testing

Test basic workflow functionality by creating simple automation workflows. Verify external service connections by testing API integrations and webhook processing.

Establish performance baselines by monitoring resource usage during typical workflow operations. Set up health checks and monitoring to detect issues early.

Security Best Practices

System-Level Security

Configure UFW (Uncomplicated Firewall) to restrict network access:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow 5678/tcp
sudo ufw enable

Implement SSH key-based authentication and disable password authentication:

# Edit SSH configuration
sudo nano /etc/ssh/sshd_config

# Set these values:
PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin no

Establish regular system update procedures:

# Create update script
cat > update.sh << 'EOF'
#!/bin/bash
apt update && apt upgrade -y
apt autoremove -y
apt autoclean
EOF

n8n-Specific Security

Implement strong password policies for n8n accounts. Store sensitive credentials in environment variables rather than hardcoding them in workflows. Regularly rotate API keys and authentication tokens.

Configure webhook security by validating request signatures and implementing rate limiting. Monitor API usage and implement access controls for sensitive workflows.

Network Security

Implement reverse proxy configurations for external access, providing SSL termination and additional security layers. Configure VPN access for remote administration when possible.

Set up network monitoring to detect unusual traffic patterns or potential security breaches. Implement intrusion detection systems for advanced threat monitoring.

Data Protection

Enable encryption for data at rest and in transit. Implement regular backup procedures with encryption and test restoration processes regularly.

Establish data retention policies complying with relevant regulations. Configure audit logging to track user activities and system changes.

Troubleshooting Common Issues

Installation Problems

Node.js Version Compatibility: Ensure you’re using a supported Node.js version. n8n requires Node.js 14 or higher, with LTS versions recommended.

# Check Node.js version
node --version

# Install specific version if needed
sudo npm install -g n@latest
sudo n lts

Docker Permission Issues: Add your user to the docker group and restart your session:

sudo usermod -aG docker $USER
newgrp docker

Port Conflicts: Check if port 5678 is already in use:

sudo netstat -tulpn | grep :5678

Change the port if necessary by modifying environment variables or Docker configurations.

Runtime Issues

Memory Problems: Monitor memory usage and increase allocation if necessary:

# Check memory usage
free -h
docker stats n8n

Service Startup Failures: Check system logs for error messages:

sudo journalctl -u n8n -f
docker logs n8n

Database Connection Errors: Verify database credentials and network connectivity:

# Test database connection
docker-compose exec postgres psql -U n8n -d n8n -c "SELECT 1;"

Network and Access Issues

Firewall Blocking: Ensure firewall rules allow access to n8n ports:

sudo ufw status
sudo ufw allow 5678/tcp

SSL Certificate Issues: Check certificate validity and renewal:

# Check certificate expiration
openssl x509 -in /path/to/cert.pem -noout -dates

Reverse Proxy Errors: Verify proxy configuration and upstream connectivity:

# Test upstream connection
curl -I http://localhost:5678

Performance Optimization and Maintenance

Resource Monitoring

Implement comprehensive monitoring for CPU, memory, and disk usage. Use tools like htop, iotop, and docker stats for real-time monitoring.

# Install monitoring tools
sudo apt install htop iotop nethogs -y

# Monitor Docker containers
docker stats --no-stream

Set up automated monitoring with tools like Prometheus and Grafana for production environments.

Database Performance Tuning

Optimize database performance through proper indexing and configuration tuning. Monitor query performance and optimize slow operations.

# PostgreSQL performance monitoring
docker-compose exec postgres psql -U n8n -d n8n -c "SELECT * FROM pg_stat_activity;"

Maintenance Schedule

Establish regular maintenance procedures including:

  • Weekly system updates and security patches
  • Monthly backup verification and restoration testing
  • Quarterly security audits and vulnerability assessments
  • Annual disaster recovery plan testing

Create automated maintenance scripts:

cat > maintenance.sh << 'EOF'
#!/bin/bash
# System updates
apt update && apt upgrade -y

# Docker cleanup
docker system prune -f

# Log rotation
journalctl --vacuum-time=30d

# Backup verification
./backup.sh
EOF

Scaling Considerations

Plan for horizontal scaling by implementing load balancing and multiple n8n instances. Configure database clustering for high availability requirements.

Consider implementing container orchestration with Kubernetes for large-scale deployments. Monitor performance metrics to identify scaling needs before capacity limits are reached.

Congratulations! You have successfully installed n8n. Thanks for using this tutorial for installing n8n workflow automation software and tools on Ubuntu 24.04 LTS Linux system. For additional help or useful information, we recommend you check the official n8n website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button