If you’ve ever wanted to automate repetitive tasks — like syncing data between apps, sending notifications, processing forms, or orchestrating complex business workflows — n8n is one of the most powerful tools available today. It’s an open-source, node-based workflow automation platform that gives you full control over your data and integrations.
Unlike SaaS-only automation tools such as Zapier or Make, n8n allows you to self-host the entire platform on your own server or local machine — and set up n8n in a way that fits your needs. This means your data stays within your infrastructure, you avoid per-task pricing, and you can customize everything to your heart’s content.
n8n (pronounced “n-eight-n“) is a fair-code licensed workflow automation tool with a visual, drag-and-drop interface. It supports over 400+ integrations — from Google Sheets and Slack to databases, APIs, and custom webhooks — and allows you to build complex automations without writing much code.
This guide focuses entirely on self-hosting, which is the preferred option for developers, DevOps teams, and privacy-conscious users.
Before diving into installation, make sure you have the following in place:
npm method).Docker method).n8n can be deployed in several ways. The right method depends on your use case, technical comfort level, and environment. Here’s an overview of the three primary methods:
Installing n8n via npm is the fastest way to get started. It requires only Node.js and is ideal for trying n8n locally before committing to a full server setup.
Running n8n as a Docker container isolates it from your host system, ensures consistent behavior across environments, and makes updates easy. This is the most popular method for production.
Docker Compose lets you define and manage multi-container setups. This is ideal when you want to run n8n alongside a PostgreSQL database, a reverse proxy, and other services — all with a single configuration file.
The table below summarizes the trade-offs:
| Feature | npm | Docker |
|---|---|---|
| n8n Setup Speed | Very Fast | Fast |
| Best For | Local Testing | Production |
| Persistence | Limited | Volume-based |
| Scalability | Low | High |
| Recommended | Beginners | Production Use |
💡 Note: For most users planning to run n8n in production, Docker or Docker Compose is the recommended approach.
This method is best for local development and quick testing. It requires Node.js to be installed on your system.
Download and install Node.js v18 or higher from https://nodejs.org. Verify the installation:
node --version
npm --version 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;
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_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:
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…
1. Introduction When you're running a web application in production, one of the first things…
1. What is a Firewall? A firewall is a security system that acts as a…
1. What is a Hypervisor? A hypervisor, also known as a Virtual Machine Monitor (VMM),…