To install n8n using npm, you must first have Node.js installed on your machine, specifically a version between 20.19 and 24.x. The quickest way to try n8n without a full commitment is by running npx n8n
in your terminal. For a more permanent, self-hosted setup, the primary command is npm install n8n -g
, which installs n8n globally and allows you to start it anytime with a simple n8n
command. This guide will walk you through these methods, plus how to update, manage versions, and configure your instance directly from the command line.
Why Choose npm for Your n8n Install?
So, you’re ready to dive into self-hosting n8n. You’ve probably seen a ton of tutorials focusing on Docker, and for good reason—it’s robust, isolated, and fantastic for production. But let’s be honest, sometimes Docker feels like bringing a bazooka to a knife fight, especially if you’re a developer who already lives and breathes in the Node.js ecosystem.
This is precisely where installing n8n with npm shines. It’s lightweight, direct, and feels incredibly natural if you’re comfortable in a terminal. You get:
- Direct Control: You’re managing the n8n process directly on your machine, no container abstraction layers.
- Simplicity: No need to learn Docker networking or volume mounting if you just want to get up and running quickly for local development.
- Speed: It’s often faster to get a local instance running with a single npm command than to pull and configure a Docker image.
Is it for everyone? Maybe not. For complex, multi-service production environments, Docker Compose is still the king. But for local development, testing new workflows, or running on a simple server where you have Node.js, the npm n8n install
method is an elegant and powerful choice.
Getting Your Environment Ready
Before we can unleash the power of automation, we need to make sure our workshop has the right tools. The setup is refreshingly simple.
The All-Important Prerequisite: Node.js
n8n is built on Node.js, so you need it installed to run n8n via npm. It’s a non-negotiable step. Critically, n8n is particular about its Node.js versions. As of writing, you’ll need a version between 20.19.x and 24.x. You can check your current version by popping open a terminal and typing:
node -v
If you don’t have it or have the wrong version, head over to the official Node.js website and grab the correct LTS (Long Term Support) version. For my fellow Windows users, if you run into snags, Microsoft has a great guide on setting up a proper Node.js environment on Windows that can save you a headache.
Your First n8n Install: Two Paths to Automation Glory
Once Node.js is ready, you have two main options for getting n8n running. Think of it as a test drive versus buying the car.
The ‘Quick Trial’ Method: npx
Want to see what n8n is all about without installing anything permanently? npx
is your best friend. It’s a package runner tool that comes with npm.
Run this single command:
npx n8n
This command temporarily downloads the latest n8n package, runs it, and then cleans up after itself when you close the process. It’s the perfect zero-commitment way to explore the UI. Once it’s running, just navigate to http://localhost:5678
in your browser, and you’re in!
The ‘I’m All In’ Method: Global npm install
Ready for a more permanent setup on your local machine or a dev server? A global installation is the way to go.
npm install n8n -g
The -g
flag tells npm to install the package globally, making the n8n
command available anywhere in your terminal. After the installation completes, you can start your instance simply by typing:
n8n
And just like with npx, you can access it at http://localhost:5678
. This instance will use a .n8n
folder in your user’s home directory to store all your workflows and credentials, so your work persists between sessions.
Managing Your n8n Instance Like a Pro
Installing is just the first step. As an n8n professional, you’ll need to update, switch versions, and handle things like webhooks. Here’s a quick command-line cheat sheet.
Goal | Command | What it Does |
---|---|---|
Update | npm update -g n8n |
Updates your global install to the latest stable version. |
Install Beta | npm install -g n8n@next |
Installs the newest, potentially unstable, pre-release version. |
Install Specific | npm install -g n8n@1.42.1 |
Installs a specific version, perfect for downgrading or matching a prod env. |
Local Tunnel | n8n start --tunnel |
Starts n8n and creates a public URL for testing webhooks. |
A Note on the Tunnel
That --tunnel
flag is incredibly useful. Let’s say you’re building a workflow that starts when you get a new message in a Slack channel. Slack needs a public URL to send that data to. The tunnel command creates a temporary, public internet address that forwards directly to your local n8n instance. It’s brilliant for development, but please heed the warning: do not use this for production. It’s not secure for sensitive data.
Real-World Scenario: Setting Up a Secure Dev Instance
I often need to test workflows that use external modules from npm, like a special data-parsing library. Installing n8n via npm makes this a breeze. Here’s a common task: setting up an instance that can use axios
inside a Code node.
-
Install n8n: First, I make sure n8n is installed globally:
npm install n8n -g
. -
Install the Module: I’ll also install my desired package. While there are a few ways to do this, for simplicity, I’ll install it globally too:
npm install axios -g
. -
Configure Environment Variables: Now, here’s the magic. n8n is highly configurable through environment variables. Before starting n8n, I need to tell it that it’s allowed to access this external module. I’ll do this in my terminal:
export NODE_FUNCTION_ALLOW_EXTERNAL=axios
(On Windows, the command is
set NODE_FUNCTION_ALLOW_EXTERNAL=axios
) -
Start n8n: Now I can start n8n with
n8n start
. My instance will now have permission torequire('axios')
inside any Code node, unlocking a huge amount of custom functionality.
This level of configuration shows why the npm n8n install
route is so beloved by developers. It integrates seamlessly into a command-line-driven workflow and provides the granular control we need to build truly custom and powerful automations.