Run the following command to install n8n as a global npm package:
npm install -g n8n This will download and install n8n along with all required dependencies.
Once installed, start n8n with:
n8n start n8n will initialize and display startup logs. By default, it listens on port 5678.
Open your browser and navigate to: http://localhost:5678.
You’ll be greeted by the n8n setup wizard, where you can create your first owner account.
💡 Note: Data is stored in SQLite by default (~/.n8n directory). This is fine for testing, but not recommended for production.
Docker provides a clean, isolated environment for running n8n. Make sure Docker is installed on your system before proceeding.
docker pull n8nio/n8n Run n8n with a mounted volume for persistent data:
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n
Breaking this down:
-p 5678:5678 — maps the container port to your host machine.-v ~/.n8n:/home/node/.n8n — persists n8n data to your local filesystem.--rm — removes the container when it stops (use without this flag for persistence).Check that the container is active:
docker ps You should see the n8n container listed. Open http://localhost:5678 to access the UI.
Docker Compose is the most robust way to self-host n8n. It allows you to define your entire setup in a single YAML file, making it easy to replicate, update, and manage.
docker-compose.yml FileCreate a new directory for your n8n setup and add a docker-compose.yml file:
mkdir n8n-setup && cd n8n-setup
nano docker-compose.yml
Paste the following configuration:
version: '3.8'
services:
n8n:
image: n8nio/n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_HOST=your-domain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://your-domain.com/
- DB_TYPE=postgresdb
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=your_password
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- postgres
postgres:
image: postgres:15
restart: unless-stopped
environment:
- POSTGRES_DB=n8n
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=your_password
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
n8n_data:
postgres_data:
docker compose up -d The -d flag runs the services in detached (background) mode. Docker will pull the necessary images and start both n8n and PostgreSQL.
docker compose ps Both the n8n and PostgreSQL services should be running.
Running n8n on a public server requires a few additional steps to make it secure and accessible.
A reverse proxy sits in front of n8n and handles HTTPS. Here’s a basic Nginx server block:
server {
server_name your-domain.com;
locations / {
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_cache_bypass $http_upgrade;
}
}
Install Certbot and obtain a free SSL certificate:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com Certbot will automatically configure HTTPS in your Nginx config and set up auto-renewal.
By default, n8n uses SQLite, which is fine for local testing but not suitable for production use. SQLite doesn’t handle concurrent access well, and backups are trickier.
Add these environment variables to your n8n service:
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=postgres
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=your_secure_password
n8n automatically runs database migrations on startup. No manual SQL scripts are required — simply start n8n and it will create all necessary tables.
Now that n8n is running, let’s build a simple workflow to see how everything fits together.
Log in to your n8n instance and click the ‘+ New Workflow‘ button in the top-right corner.
Every workflow starts with a trigger. Click the ‘+‘ button to open the node panel and search for one of these popular triggers:
Add action nodes to perform tasks. For example:
Drag a line from the output of your trigger to the input of the action node to connect them.
Click ‘Execute Workflow’ to test your workflow manually. Once you’re satisfied, toggle the Active switch in the top-right to enable it. n8n will now run the workflow automatically based on your trigger conditions.
For n8n to serve you reliably, it needs to stay running even after crashes or server reboots.
npm install -g pm2
pm2 start n8n
pm2 save
pm2 startup
PM2 will automatically restart n8n if it crashes and launch it on server boot.
In your docker-compose.yml or Docker run command, set the restart policy:
restart: unless-stopped This ensures n8n restarts automatically after crashes or reboots (unless you manually stop it).
Create a systemd service file at /etc/systemd/system/n8n.service to manage n8n as a system service. Use systemctl enable n8n and systemctl start n8n to activate it.
Congratulations! You now have a fully self-hosted n8n instance up and running. Let’s recap what you’ve accomplished:
Now that the foundation is in place, here’s what you can explore:
1. Introduction WordPress 6.9, codenamed "Gene," is the final major release of 2025 and one…
1. Introduction to Containerization 1.1 What Is Containerization and Why It Matters Modern software development…
Introduction Survival games have become one of the most enduring and beloved genres in modern…
1. What is Node.js? Node.js lets you use JavaScript to build the "brain" of a…
1. Introduction If you have ever shopped for a new SSD or tried to upgrade…