The Easiest Way to Install n8n on Ubuntu 22.04 VPS

The easiest way to install n8n on a newly deployed Ubuntu 22.04 VPS server is by using Docker. This method requires minimal steps and ensures a full installation. Here’s a step-by-step guide:

Step 1: Update Your System

sudo apt update && sudo apt upgrade -y

Step 2: Install Docker and Dependencies

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
docker --version

Step 3: Create Directories for n8n Data

mkdir -p ~/.n8n
sudo chown -R 1000:1000 ~/.n8n
sudo chmod -R 755 ~/.n8n

Step 4: Pull and Run n8n Docker Container

docker pull n8nio/n8n
docker run -d --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

Step 5: Access n8n

Visit: http://YOUR_SERVER_IP:5678 (replace with your VPS IP)

Step 6: Set n8n to Start on Boot

docker update --restart=always n8n


Configure SSL with Your Domain (e.g. n8n.tel)

You have two options for setting up SSL. Option 1 using Nginx and Certbot is recommended.

Option 1: Nginx as a Reverse Proxy with Certbot (Recommended)

1. Install Nginx

sudo apt install -y nginx

2. Configure Nginx

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

Paste the following configuration (replace n8n.tel with your domain):

server {
    listen 80;
    server_name n8n.tel;

    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;
    }
}

3. Enable and Test Configuration

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

4. Install Certbot & Get SSL Certificate

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d n8n.tel

5. Verify and Test Auto-Renewal

sudo systemctl list-timers | grep certbot
sudo certbot renew --dry-run

Your n8n instance should now be accessible at https://n8n.tel.

Option 2: Direct SSL Configuration in Docker (Advanced)

mkdir -p ~/n8n/certificates

# Prepare certificate environment variables:
N8N_SSL_CERT=$(cat /path/to/cert.pem)
N8N_SSL_KEY=$(cat /path/to/privkey.pem)

docker run -d --restart unless-stopped -it \
  --name n8n \
  -p 443:5678 \
  -e N8N_HOST="n8n.tel" \
  -e WEBHOOK_TUNNEL_URL="https://n8n.tel/" \
  -e WEBHOOK_URL="https://n8n.tel/" \
  -e N8N_SSL_CERT="$N8N_SSL_CERT" \
  -e N8N_SSL_KEY="$N8N_SSL_KEY" \
  -v n8n_data:/home/node/.n8n \
  n8nio/n8n

Note: You’ll need to manually renew SSL certificates with this method.

Helpful Resources