Home » n8n» n8n how to install: Docker and Node.js on a VPS

N8n how to install?

This guide explains n8n how to install on a VPS using Docker or Node.js. You can install n8n quickly with Docker Compose on your VPS by following the commands and steps below.

What You Need

  • VPS with Ubuntu 20.04 or 22.04 and a non-root sudo user.
  • Domain name (recommended) or public IP for web access.
  • Docker and Docker Compose, or Node.js 18+ if running without Docker.
  • Basic SSH access and a text editor (nano or vim).

Install n8n how to install with Docker

This section shows Docker steps. Use Docker for easier updates and isolation.

Step 1: Install Docker and Docker Compose

sudo apt update
sudo apt install -y docker.io docker-compose
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker

Log out and back in if your user is not in the docker group yet.

Step 2: Create a project folder and an env file

mkdir -p ~/n8n && cd ~/n8n
cat > .env <

Step 3: Add a Docker Compose file

cat > docker-compose.yml <<'YAML'
version: '3.8'
services:
  postgres:
    image: postgres:14
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${DB_POSTGRESDB_USER}
      POSTGRES_PASSWORD: ${DB_POSTGRESDB_PASSWORD}
      POSTGRES_DB: ${DB_POSTGRESDB_DATABASE}
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
  n8n:
    image: n8nio/n8n:latest
    restart: unless-stopped
    env_file: .env
    ports:
      - 5678:5678
    depends_on:
      - postgres
    volumes:
      - ./n8n-data:/home/node/.n8n
YAML

Step 4: Start n8n

docker-compose up -d

Visit http://your-server-ip:5678 or your domain to open the n8n UI. Use the basic auth credentials you set.

How to Install n8n how to install with Node.js

Running n8n with Node.js is possible for development or low-scale use. This uses npm and a systemd service.

Quick Node.js install steps

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs build-essential
npm install -g n8n
# Start manually
n8n

For production, run n8n behind a reverse proxy and create a systemd service file. Use a process manager or container in production.

Update

To update Docker setup, pull the latest image and restart.

cd ~/n8n
docker-compose pull n8n
docker-compose up -d --remove-orphans
# Optional: prune old images
docker image prune -f

Security

  • Use N8N_BASIC_AUTH and strong passwords in .env.
  • Put n8n behind a TLS reverse proxy (Nginx or Traefik) and enable Let's Encrypt.
  • Open only required ports. Use UFW to allow SSH and your proxy ports.
  • Secure your Postgres password and use a separate DB user for n8n.
  • Keep the OS and Docker updated. Backup the n8n-data and database regularly.

Done

You now have a working n8n instance on a VPS. Use Docker Compose for easy management. Test workflows and secure access before production use.


Neil
Written by Neil

Neil is a true n8n geek who lives and breathes workflow automation. He dives deep into nodes, triggers, webhooks, custom logic, and self-hosting setups, sharing everything he learns about n8n on AutomationCompare.com. As part of a broader team of automation specialists, Neil focuses purely on mastering n8n and helping others unlock its full potential.

Keep Reading

Scroll to Top