Step 1: Install or Update n8n
Install n8n globally via npm:
npm install -g n8n
Install n8n globally via npm with their next channel for v2:
npm install -g n8n@next
To update an existing installation to the latest version:
npm update -g n8n
Verify the installation:
n8n --version
Step 2: Install PM2
PM2 is a production-ready process manager for Node.js applications. Running n8n directly in a terminal means it stops when you close the session. PM2 solves this by:
- Keeping n8n running in the background
- Automatically restarting it if it crashes
- Starting n8n on system boot
- Managing environment variables cleanly
- Providing monitoring and log management
Install PM2 globally:
npm install -g pm2
Step 3: Create the PM2 Configuration File
Create a configuration file in your home directory. This file tells PM2 how to run n8n and what environment variables to use.
nano ~/n8n.config.js
Add the following content:
module.exports = {
apps: [{
name: 'n8n',
script: 'n8n',
env: {
NODE_ENV: 'production',
N8N_RELEASE_TYPE: '<stable/next>',
N8N_HOST: '0.0.0.0',
N8N_PORT: '5678',
WEBHOOK_URL: '<https://your-domain.com/>',
}
}]
};
Save and exit (Ctrl+X, then Y, then Enter).\
Environment Variables Explained
| Variable | Purpose |
|---|---|
NODE_ENV | Set to production to remove the [DEV] tag in the browser and enable production optimizations |
N8N_HOST | The IP address n8n listens on. Use 0.0.0.0 to accept connections from any interface, or a specific IP to restrict access |
N8N_PORT | The port n8n runs on (default: 5678) |
WEBHOOK_URL | The public URL for webhooks. Required for triggers and external integrations to reach your instance |
n8n, a tool we use almost every day here at Azpivi, just had a major release. v2.0 beta is now ready to test out in their next release branch. While version 1.0 was about stability and reaching “maturity,” Version 2.0 is an architectural shift designed to make n8n enterprise-ready and developer-friendly. The shift is comparable to moving from “writing scripts directly on a server” to “using a proper CI/CD pipeline.”
Here is the breakdown of some of the major changes.
1. The End of “Hot Edits” (Draft vs. Publish)
The single biggest workflow change in v2 is the separation of development and production.
- In v1: There was only one button: Save. If you saved a workflow, you effectively deployed it. Debugging a live production workflow was risky; if you hit save on a broken node, you broke production immediately.
- In v2: You now have Draft and Published states. You can edit, debug, and break your “Draft” version as much as you want without affecting the live version running in the background. You must explicitly click Publish to push your changes to production.
2. True Human-in-the-Loop
If you build AI agents or approval flows, v2 fixes a major architectural limitation regarding long-running tasks.
- The Fix: In v1, if a parent workflow called a sub-workflow that needed to wait for a human approval (e.g., via Slack), the connection would often time out or return incorrect results. In v2, this is native. The Parent Workflow effectively “pauses” and waits for the Sub-workflow to complete—even if it takes days for a human to click “Approve.” Once approved, the data flows back to the Parent seamlessly.
The Architecture of Stability
This is arguably the most critical “under the hood” change in v2, specifically regarding stability and security.
In v1, running custom code (JavaScript/Python) was like letting a stranger drive your car while you were sitting in the passenger seat. If they crashed, you both crashed. In v2, with Task Runners, it’s like controlling a remote-controlled car. If the RC car crashes, you are safe standing on the sidewalk.
v1: In-Process Execution (The Risk)
Previously, custom code ran inside the same operating system process as the main n8n server.
- The Crash Risk: If your JavaScript had a memory leak or an infinite loop, it consumed the host server’s resources. This would cause the entire n8n instance to crash, killing all other active workflows and webhooks.
- The Security Risk: Because code ran in the main process, a clever user could theoretically access internal server environment variables.
v2: Task Runners (The Solution)
Version 2 introduces Task Runners—separate processes dedicated entirely to executing custom code.
- Isolation: When a workflow hits a Code Node, n8n sends the data to the Task Runner. If your Python script crashes, only the Task Runner fails. The main n8n server stays alive, simply marking that specific execution as an “Error.”
- Performance: Heavy data transformation tasks (like processing large JSON files) no longer block the main event loop. Your webhook listeners remain responsive even while heavy computation happens in the background.
Python as a First-Class Citizen
This architecture moves Python from “experimental” to stable. The old Pyodide-based Python node has been removed and replaced with a native Python implementation running on Task Runners. Because the Task Runner is a native Python environment, it supports pip installs and provides a reliable playground for data scientists who prefer Python over JS.
Summary Checklist for Upgrading
If you are moving to v2, be aware of these requirements:
- Database: MySQL and MariaDB are no longer supported. You must use PostgreSQL or SQLite. If you’re currently on MySQL/MariaDB, migrate your data before upgrading.
- Docker: You will likely need to adjust your container setup to include the new “Task Runner” sidecar containers if you want code isolation in external mode.
- Variables: Code nodes can no longer access
process.envby default; you must explicitly allowlist the variables you want to expose.
This is just an overview of the changes; please check out their official docs, website, and blog post on this update!
Installing n8n with NPM
This quick guide walks through setting up n8n as a persistent background service using PM2.
Prerequisites
Install Node.js, npm, and nvm. Visit the official download page for an updated command and different platforms.
Step 1: Install or Update n8n
Install n8n globally via npm:
npm install -g n8n
Install n8n globally via npm with their next channel for v2:
npm install -g n8n@next
To update an existing installation to the latest version:
npm update -g n8n
Verify the installation:
n8n --version
Step 2: Install PM2
PM2 is a production-ready process manager for Node.js applications. Running n8n directly in a terminal means it stops when you close the session. PM2 solves this by:
- Keeping n8n running in the background
- Automatically restarting it if it crashes
- Starting n8n on system boot
- Managing environment variables cleanly
- Providing monitoring and log management
Install PM2 globally:
npm install -g pm2
Step 3: Create the PM2 Configuration File
Create a configuration file in your home directory. This file tells PM2 how to run n8n and what environment variables to use.
nano ~/n8n.config.js
Add the following content:
module.exports = {
apps: [{
name: 'n8n',
script: 'n8n',
env: {
NODE_ENV: 'production',
N8N_RELEASE_TYPE: '<stable/next>',
N8N_HOST: '0.0.0.0',
N8N_PORT: '5678',
WEBHOOK_URL: '<https://your-domain.com/>',
}
}]
};
Save and exit (Ctrl+X, then Y, then Enter).
Environment Variables Explained
| Variable | Purpose |
|---|---|
NODE_ENV | Set to production to remove the [DEV] tag in the browser and enable production optimizations |
N8N_HOST | The IP address n8n listens on. Use 0.0.0.0 to accept connections from any interface, or a specific IP to restrict access |
N8N_PORT | The port n8n runs on (default: 5678) |
WEBHOOK_URL | The public URL for webhooks. Required for triggers and external integrations to reach your instance |
Step 4: Start n8n with PM2
Launch n8n using the configuration file:
pm2 start ~/n8n.config.js
Step 5: Enable Startup on Boot
Generate the startup script and save the current process list:
pm2 startup
This outputs a command you need to run with sudo—copy and execute it. Then save the process list:
pm2 save
Now n8n will automatically start when your system boots.
PM2 Command Reference
Basic Process Management
| Command | Description |
|---|---|
pm2 start ~/n8n.config.js | Start n8n using the config file |
pm2 stop n8n | Stop the n8n process |
pm2 restart n8n | Restart n8n |
pm2 delete n8n | Remove n8n from PM2’s process list |
Monitoring and Logs
| Command | Description |
|---|---|
pm2 list | Show all managed processes and their status |
pm2 monit | Real-time monitoring dashboard (CPU, memory, logs) |
pm2 logs n8n | View n8n logs (Ctrl+C to exit) |
pm2 logs n8n --lines 100 | View last 100 lines of logs |
Configuration Changes
When you modify n8n.config.js, apply the changes with:
pm2 delete n8n
pm2 start ~/n8n.config.js
pm2 save
Alternatively, for environment variable updates only:
pm2 restart n8n --update-env
Useful Diagnostics
| Command | Description |
|---|---|
pm2 show n8n | Detailed information about the n8n process |
pm2 env 0 | Show environment variables for process ID 0 |