System Maintenance: Notes on nvm
npx n8n
Your Node.js version 18.16.1 is currently not supported by n8n.
Please use a Node.js version that satisfies the following version range: >=18.17 <= 22
Running n8n threw an error saying the Node version has to be greater than 18.17, but I’m on 18.16.1. That version is a bit old — probably from 2023 — but it matches the environment of 星球大作战 on my server, so I want to keep it.
Backstory
nvm can be used to manage Node.js versions and switch between them quickly. I don’t use it much day to day, but I had a vague impression of it, so I searched and found I’d written about it back in August 2024.
Back then I installed nvm to solve the “npm install -g always gives a permission error” problem, hoping to use it to manage nodejs and maintain directory permissions. But I never used it to manage nodejs — instead I managed directory permissions by hand, adding the path ~/.npm-global to npm config so that npm install -g installed to a different location, which solved the permission problem. That involved hexo and yarn, both of which were installed into ~/.npm-global after the change.
Today’s problem is that the version isn’t new enough and I need to upgrade nodejs. I don’t really need to keep multiple versions side by side, but nvm can help me preserve the system version.
How nvm manages things:
Use the following command to list the Node.js versions managed by nvm:
nvm list
You can install a new Node.js version with nvm and switch to it, to verify that nvm works properly.
# 安装最新的长期支持版(LTS)
nvm install --lts
# 使用刚安装的版本
nvm use --lts
# 查看当前使用的 Node.js 版本
node -v
Let’s look at my current system state:
rhett@Mousebomb-MacStudio .nvm % nvm list
-> system
iojs -> N/A (default)
node -> stable (-> N/A) (default)
unstable -> N/A (default)
**lts/*** -> **lts/iron** (-> N/A)
**lts/argon** -> v4.9.1 (-> N/A)
**lts/boron** -> v6.17.1 (-> N/A)
**lts/carbon** -> v8.17.0 (-> N/A)
**lts/dubnium** -> v10.24.1 (-> N/A)
**lts/erbium** -> v12.22.12 (-> N/A)
**lts/fermium** -> v14.21.3 (-> N/A)
**lts/gallium** -> v16.20.2 (-> N/A)
**lts/hydrogen** -> v18.20.4 (-> N/A)
**lts/iron** -> v20.16.0 (-> N/A)
rhett@Mousebomb-MacStudio .nvm % nvm --version
0.40.0
The result above 👆 is what I get right now, which means it’s using the system nodejs (the one I installed earlier from the official Node.js website).
After searching online, I found that after switching to each Node.js version, manually running the following command carries over the global package path I already set up, so that I can keep using hexo and the rest:
npm config set prefix '~/.npm-global'
The actual process
First install
nvm install --lts
Hit this error:
Your user’s .npmrc file (${HOME}/.npmrc)
has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.
Run `nvm use --delete-prefix` to unset it.
Removing –prefix
Need to run nvm use --delete-prefix system (done). Or manually edit the contents of .npmrc, changing from
registry=https://registry.npmmirror.com/
prefix=/Users/rhett/.npm-global
to registry=https://registry.npmmirror.com/ (done)
Reinstall nodejs and set the global package path
Reinstall the latest version, with a shared directory (done, didn’t work):nvm install 22.15.0 --shared=~/.npm-global
I don’t know whether it worked, but even if it wastes a bit of space, no big deal.
Let me verify:npm install -g n8n
Well well, sure enough, the earlier attempt didn’t work — n8n got installed to the nvm-managed location:/Users/rhett/.nvm/versions/node/v22.15.0/lib/node_modules/n8n
and symlinked to /Users/rhett/.nvm/versions/node/v22.15.0/bin
Hmm, the earlier install probably had issues. I uninstalled it and installed again:
nvm uninstall 22.15.0
nvm install 22.15.0 --shared=~/.npm-global
npm install -g n8n
It still installed inside .nvm. Whatever — --shared probably doesn’t do anything, Doubao was lying to me.
Anyway, there wasn’t much installed in .npm-global before, and it still works, so I’ll leave it alone for now.
Running n8n
When I ran it, it actually told me Safari won’t work.
Your n8n server is configured to use a secure cookie,
however you are either visiting this via an insecure URL, or using Safari.
To fix this, please consider the following options:
- Setup TLS/HTTPS (recommended), or
- If you are running this locally, and not using Safari, try using localhostinstead
- If you prefer to disable this security feature (not recommended), set the environment variable
N8N_SECURE_COOKIEtofalse
The reason is that Safari is stricter and won’t send secure cookies over non-HTTPS, but I’m testing locally.
I’ll just use Chrome for now as a temporary fix.