How To Setup n8n
Cloud, NPM, Docker, and Docker Compose. Every method explained step by step.
Choose Your Method
n8n gives you three installation paths. Each one trades convenience for control. The right choice depends on what you need right now, not what you might need six months from now. You can always migrate later.
n8n Cloud is the managed option. You sign up, and n8n handles the server, SSL, backups, and updates. It takes about two minutes. NPM installs n8n as a global Node.js package on your local machine. It is fast for testing and learning, but not suitable for production. Docker is the standard for production deployments. It gives you isolation, reproducibility, and easy upgrades.
Quick comparison:
- n8n Cloud – Easiest. Managed hosting, automatic updates, SSL included. Best for beginners and teams.
- NPM – Fastest to start. Local only. Best for development and learning.
- Docker – Production standard. Full control. Best for VPS and server deployments.
- Docker Compose – Docker with PostgreSQL, environment config, and restart policies. The recommended production setup.
If you are brand new to n8n and just want to try it, start with Cloud. If you are a developer who wants to run n8n alongside other tools on your machine, use NPM. If you are deploying n8n for a team or a client, go straight to Docker Compose with PostgreSQL.
Method 1: n8n Cloud
n8n Cloud is the fully managed option. You do not install anything, configure any server, or worry about SSL certificates. n8n runs the infrastructure and you build workflows.
Go to app.n8n.cloud, create an account, and your workspace is ready in seconds. The free trial does not require a credit card. Once your trial starts, you get a fully functional n8n instance with a public URL, webhook endpoints, and the complete node library.
What you get with Cloud:
- Automatic updates to the latest n8n version
- SSL/TLS encryption on your workspace URL
- Managed backups of your workflows and credentials
- Scaling and performance handled by n8n
- Built-in execution history and logging
Cloud is best for beginners, solo operators, and teams who do not want to manage infrastructure. The tradeoff is cost: after the free trial, you pay a monthly fee based on your plan tier. For a detailed breakdown of pricing and features across tiers, see our n8n Cloud Plans guide.
Not sure whether Cloud or self-hosted is right for you? Read our Cloud vs. Self-Hosted comparison for a full breakdown of costs, control, and trade-offs.
Method 2: NPM (Local Development)
Installing n8n via NPM is the fastest way to get a local instance running. You need Node.js version 18 or higher installed on your machine. Check your version with node -v. If you need to install or update Node.js, use nodejs.org or a version manager like nvm.
npm install -g n8n
n8n start
After running n8n start, open your browser and go to http://localhost:5678. You will see the n8n setup screen where you create your owner account. All data is stored locally in ~/.n8n/ by default, including workflows, credentials, and execution logs.
You can also run n8n without installing it globally by using npx:
npx n8n
NPM is not recommended for production. It uses SQLite by default, has no built-in process management, and does not survive server reboots without additional configuration. Use it for local development, testing, and learning. For production, use Docker or Docker Compose.
Good for: local development, learning n8n, testing workflows before deployment, quick prototyping. Not good for: production servers, team environments, anything that needs to stay running 24/7.
Method 3: Docker
Docker is the production standard for self-hosted n8n. It gives you an isolated, reproducible environment that you can deploy on any VPS, cloud server, or local machine with Docker installed. Upgrades are as simple as pulling a new image.
Make sure Docker is installed on your machine. You can verify with docker --version. If you need to install it, follow the official instructions at docs.docker.com.
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
docker.n8n.io/n8nio/n8n
Here is what each flag does:
-itruns the container in interactive mode with a terminal attached--rmremoves the container when it stops (the data persists in the volume)--name n8ngives the container a recognizable name-p 5678:5678maps port 5678 on your host to port 5678 in the container-v ~/.n8n:/home/node/.n8nmounts a host directory as a volume so your data persists between container restarts
After running this command, open http://localhost:5678 (or your server IP) in your browser. The volume mount at ~/.n8n ensures your workflows, credentials, and execution history survive container restarts and image upgrades.
For production use, remove the --rm flag and add --restart always so the container restarts automatically after reboots. Better yet, use Docker Compose as described in the next section.
For a complete guide on deploying n8n on a VPS with Docker, including domain setup and SSL, see our VPS Self-Hosting guide.
Docker Compose for Production
For any serious deployment, Docker Compose is the recommended approach. It lets you define n8n, its database, and all configuration in a single file. The setup below uses PostgreSQL instead of the default SQLite, which is critical for production. SQLite does not handle concurrent access well, and you will hit scaling limits quickly.
version: "3.8"
services:
n8n:
image: docker.n8n.io/n8nio/n8n
container_name: n8n
restart: always
ports:
- "5678:5678"
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=changeme
- N8N_HOST=your-domain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://your-domain.com/
- N8N_ENCRYPTION_KEY=your-random-encryption-key
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
postgres:
image: postgres:16
container_name: n8n-postgres
restart: always
environment:
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=changeme
- POSTGRES_DB=n8n
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U n8n"]
interval: 10s
timeout: 5s
retries: 5
volumes:
n8n_data:
postgres_data:
Key sections explained:
restart: alwaysensures both containers restart after server reboots or crashesDB_TYPE=postgresdbswitches n8n from SQLite to PostgreSQLdepends_onwith a health check ensures n8n waits for PostgreSQL to be ready before startingN8N_ENCRYPTION_KEYencrypts stored credentials. Set this once and never change it, or you will lose access to all saved credentialsWEBHOOK_URLmust match your public domain so webhook triggers work correctly- Named volumes (
n8n_data,postgres_data) persist data independently of the containers
docker compose up -d
Change the default passwords. Replace changeme with strong, unique passwords before deploying. Generate an encryption key with openssl rand -hex 32. Never commit secrets to version control.
Reverse proxy for SSL: In production, you should place a reverse proxy like Caddy or Nginx in front of n8n to handle SSL termination. Caddy is the easiest option because it provisions Let's Encrypt certificates automatically. Point your domain to your server, add a Caddyfile that reverse-proxies to localhost:5678, and you are done.
Environment Variables
n8n is configured almost entirely through environment variables. These are the ones you will use most often. Set them in your docker-compose.yml, your .env file, or your shell environment for NPM installs.
-
N8N_HOSTThe domain or IP address where n8n is accessible. Example:
n8n.yourdomain.com. Used for generating correct URLs in the UI and webhook endpoints. -
N8N_PORTThe port n8n listens on. Defaults to
5678. Change this if you have port conflicts or want to run on a different port. -
N8N_PROTOCOLSet to
httpswhen running behind a reverse proxy with SSL. Defaults tohttp. -
WEBHOOK_URLThe public URL for incoming webhooks. Must include the protocol. Example:
https://n8n.yourdomain.com/. If this is not set correctly, webhook triggers will generate URLs that external services cannot reach. -
N8N_ENCRYPTION_KEYA random string used to encrypt stored credentials. Set this once and never change it. If you lose or change this key, all saved credentials become unreadable and you will need to re-enter them. Generate one with
openssl rand -hex 32. -
DB_TYPEThe database backend. Options:
sqlite(default) orpostgresdb. Use PostgreSQL for any production deployment. -
DB_POSTGRESDB_HOST,DB_POSTGRESDB_PORT,DB_POSTGRESDB_DATABASE,DB_POSTGRESDB_USER,DB_POSTGRESDB_PASSWORDConnection details for your PostgreSQL database. Only needed when
DB_TYPE=postgresdb. -
EXECUTIONS_MODESet to
queueto use Redis-backed queue mode for scaling n8n across multiple instances. Defaults toregular(single instance). Queue mode requires a Redis instance. -
N8N_BASIC_AUTH_ACTIVE,N8N_BASIC_AUTH_USER,N8N_BASIC_AUTH_PASSWORDLegacy basic authentication for the n8n UI. In current versions of n8n, user authentication is built in and these variables are deprecated. Only relevant if you are running an older version.
For the complete list of environment variables, see the official n8n environment variables reference.
First Steps After Setup
Once n8n is running and you have created your owner account, here is what to do next. These steps apply regardless of which installation method you used.
Create your first workflow. Click the "New Workflow" button, add a Manual Trigger node, connect it to a second node (try the HTTP Request node to fetch data from a public API), and execute it. This gets you familiar with the canvas, the node system, and how data flows between nodes. For a full walkthrough, see our Build Your First Workflow guide.
Set up credentials. Go to Settings → Credentials and add connections for the services you use. Gmail, Slack, Google Sheets, Notion, and similar services all require OAuth2 or API key credentials. n8n encrypts all credentials at rest using your N8N_ENCRYPTION_KEY.
Explore the node library. n8n has 400+ built-in nodes covering everything from databases to AI providers. Open the node panel (click the + button on the canvas) and browse by category. If a service you need is not listed, the HTTP Request node can connect to any REST API.
Enable community nodes. Community nodes are third-party integrations built by the n8n community. Go to Settings → Community Nodes to browse and install them. This unlocks hundreds of additional integrations. For more on the community edition and what it includes, see our Community Edition guide.
Troubleshooting Common Issues
These are the problems people run into most often when setting up n8n. Click any issue to expand.
Port 5678 is already in use
- Cause: Another process is already using port 5678. This could be another n8n instance, a development server, or any other application.
- Fix: Find what is using the port with
lsof -i :5678(macOS/Linux) ornetstat -ano | findstr :5678(Windows). Kill the process, or run n8n on a different port by settingN8N_PORT=5679in your environment or passing-p 5679:5678in your Docker command.
Permission denied on NPM install
- Cause: Global npm packages require write access to system directories. This is common on macOS and Linux without a Node version manager.
- Fix (recommended): Use
npx n8ninstead of installing globally. This runs n8n without needing write permissions to global directories. - Fix (alternative): Install Node.js via
nvm(Node Version Manager), which installs packages in your home directory. Or usesudo npm install -g n8nif you understand the security implications.
Docker container won't start
- Check the logs: Run
docker logs n8nto see what is happening. Most issues show a clear error message. - Port conflict: Make sure port 5678 is not already in use. Use
docker psto see running containers. - Volume permissions: The n8n container runs as user
node(UID 1000). Make sure the host directory you mount has the correct permissions:sudo chown -R 1000:1000 ~/.n8n. - Database not ready: If using Docker Compose with PostgreSQL, make sure the
depends_onhealth check is configured. Without it, n8n may try to connect before PostgreSQL is ready.
Forgot owner account password
- CLI reset: Run
n8n user-management:resetfrom inside the container or on the host where n8n is installed. This resets the owner account and lets you set a new password on next login. - Docker: Run
docker exec -it n8n n8n user-management:resetto execute the reset command inside the running container.
Webhook URL not working
- Cause: The
WEBHOOK_URLenvironment variable is not set or does not match your public domain. n8n generates webhook URLs based on this variable. If it points tolocalhost, external services cannot reach it. - Fix: Set
WEBHOOK_URL=https://your-domain.com/in your environment. Make sure the URL includes the protocol (https://) and a trailing slash. Restart n8n after changing the variable. - Also check: Your firewall allows incoming traffic on port 5678 (or your proxy port). Your reverse proxy is correctly forwarding requests. Your DNS points to the right server IP.
Database connection errors (PostgreSQL)
- Wrong credentials: Double-check that
DB_POSTGRESDB_USER,DB_POSTGRESDB_PASSWORD, andDB_POSTGRESDB_DATABASEmatch what you configured in your PostgreSQL service. - Host not reachable: If using Docker Compose, the host should be the service name (
postgres), notlocalhost. Docker networking resolves service names automatically. - Database does not exist: Make sure the
POSTGRES_DBenvironment variable on the PostgreSQL container matchesDB_POSTGRESDB_DATABASEon the n8n container. PostgreSQL creates the database on first start ifPOSTGRES_DBis set. - Port mismatch: The default PostgreSQL port is 5432. If you changed it, update
DB_POSTGRESDB_PORTaccordingly.
The Short Version
For trying n8n: go to app.n8n.cloud and sign up. Two minutes, no credit card. For local development: npx n8n. For production: use the Docker Compose file above with PostgreSQL, set your N8N_ENCRYPTION_KEY and WEBHOOK_URL, put a reverse proxy in front for SSL, and you are production-ready. Everything else is configuration.
