This guide will help you install n8n on a Linux server (Ubuntu) using Docker. You do not need advanced technical knowledge. Just follow the steps one by one.
What You Need
- A Linux VPS (Ubuntu 22.04 or newer)
- SSH access to your server
- Basic ability to copy and paste commands
Step 1: Connect to Your Server
Open your terminal and connect using SSH:
ssh youruser@your_server_ip
Step 2: Update Your Server
Always update first:
sudo apt update && sudo apt -y upgrade
Step 3: Install Docker
Docker is required to run n8n.
sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo $VERSION_CODENAME) 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-buildx-plugin docker-compose-plugin
Check if Docker works:
docker --version
docker compose version
Step 4: Create n8n Folder
sudo mkdir -p /opt/n8n
sudo chown -R $USER:$USER /opt/n8n
cd /opt/n8n
Step 5: Create Environment File
Create a file that stores settings:
cat > .env << 'EOF'
POSTGRES_DB=n8n
POSTGRES_USER=n8n
POSTGRES_PASSWORD=replace_with_strong_password
N8N_HOST=localhost
N8N_PORT=5678
N8N_PROTOCOL=http
WEBHOOK_URL=http://localhost:5678/
TZ=Europe/Amsterdam
EOF
Important: Replace replace_with_strong_password with a secure password.
Step 6: Create Docker Compose File
cat > docker-compose.yml << 'EOF'
services:
postgres:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
TZ: ${TZ}
volumes:
- postgres_data:/var/lib/postgresql/data
n8n:
image: docker.n8n.io/n8nio/n8n:latest
restart: unless-stopped
ports:
- "5678:5678"
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: ${POSTGRES_DB}
DB_POSTGRESDB_USER: ${POSTGRES_USER}
DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
N8N_HOST: ${N8N_HOST}
N8N_PORT: ${N8N_PORT}
N8N_PROTOCOL: ${N8N_PROTOCOL}
WEBHOOK_URL: ${WEBHOOK_URL}
TZ: ${TZ}
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- postgres
volumes:
n8n_data:
postgres_data:
EOF
Step 7: Start n8n
docker compose up -d
Check if everything is running:
docker compose ps
Step 8: Open n8n in Your Browser
Go to:
http://your_server_ip:5678
You will see the n8n setup screen. Create your admin account and you are ready.
How to Update n8n Later
cd /opt/n8n
docker compose pull
docker compose up -d
Important (Production Use)
If you want to use n8n professionally:
- Use a domain name
- Install SSL (HTTPS)
- Use a reverse proxy (like Nginx Proxy Manager)
- Do not leave port 5678 open publicly
Done
You now have a working n8n installation with database and persistent storage.