[Mac] 安裝 nvm 來管理不同的 Node.js 版本
今天想要來試裝 n8n 時,發現我的 Node.js 是 21.6.1 版,
結果它建議使用 18 或 20 版:
$ npx n8n Need to install the following packages: n8n@1.26.0 Ok to proceed? (y) y npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@azure/msal-node@1.18.4', npm WARN EBADENGINE required: { node: '10 || 12 || 14 || 16 || 18' }, npm WARN EBADENGINE current: { node: 'v21.6.1', npm: '10.2.4' } npm WARN EBADENGINE } ^@(#########⠂⠂⠂⠂⠂⠂⠂⠂⠂) ⠙ reify:@msgpackr-extract/msgpackr-extract-darwin-arm64: timing reifyNode:node_modules/@msgpackr-extract/msgpackr-extrac npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs npm WARN deprecated @azure/msal-node@1.18.4: A newer major version of this library is available. Please upgrade to the latest available version. npm WARN deprecated dommatrix@1.0.3: dommatrix is no longer maintained. Please use @thednp/dommatrix. npm WARN deprecated superagent@7.1.6: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) npm WARN deprecated json-schema-ref-parser@9.0.9: Please switch to @apidevtools/json-schema-ref-parser npm WARN deprecated @azure/msal-browser@2.38.3: A newer major version of this library is available. Please upgrade to the latest available version. npm WARN deprecated infisical-node@1.3.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm WARN deprecated debuglog@1.0.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. Your Node.js version (21.6.1) is currently not supported by n8n. Please use Node.js v18 (recommended), or v20 instead!
要管理 Node.js 版本的話,可以在 Mac 上用 Homebrew 安裝 nvm 這個套件:
$ brew install nvm ==> Downloading https://ghcr.io/v2/homebrew/core/nvm/manifests/0.39.7 ######################################################################################################################################## 100.0% ==> Fetching nvm ==> Downloading https://ghcr.io/v2/homebrew/core/nvm/blobs/sha256:fafb27126e5f79d1b2cd4f92a47a1ef186b020be0217fd8cc79d5d12d4e64d49 ######################################################################################################################################## 100.0% ==> Pouring nvm--0.39.7.all.bottle.tar.gz ==> Caveats Please note that upstream has asked us to make explicit managing nvm via Homebrew is unsupported by them and you should check any problems against the standard nvm install method prior to reporting. You should create NVM's working directory if it doesn't exist: mkdir ~/.nvm Add the following to your shell profile e.g. ~/.profile or ~/.zshrc: export NVM_DIR="$HOME/.nvm" [ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion You can set $NVM_DIR to any location, but leaving it unchanged from /usr/local/Cellar/nvm/0.39.7 will destroy any nvm-installed Node installations upon upgrade/reinstall. Type `nvm help` for further information. Bash completion has been installed to: /usr/local/etc/bash_completion.d ==> Summary 🍺 /usr/local/Cellar/nvm/0.39.7: 9 files, 194.2KB ==> Running `brew cleanup nvm`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
安裝完有訊息說要修改 ~/.bash_profile,
就在裡面加入下面這幾行:
export NVM_DIR="$HOME/.nvm" [ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
開一個新的 shell,已經可以使用 nvm 了:
$ nvm Node Version Manager (v0.39.7) Note: <version> refers to any version-like string nvm understands. This includes: - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1) - default (built-in) aliases: node, stable, unstable, iojs, system - custom aliases you define with `nvm alias foo` Any options that produce colorized output should respect the `--no-colors` option. Usage: nvm --help Show this message --no-colors Suppress colored output nvm --version Print out the installed version of nvm nvm install [<version>] Download and install a <version>. Uses .nvmrc if available and version is omitted. The following optional arguments, if provided, must appear directly after `nvm install`: -s Skip binary download, install from source only. -b Skip source download, install from binary only. --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number> --lts When installing, only select from LTS (long-term support) versions --lts=<LTS name> When installing, only select from versions for a specific LTS line --skip-default-packages When installing, skip the default-packages file if it exists --latest-npm After installing, attempt to upgrade to the latest working npm on the given node version --no-progress Disable the progress bar on any downloads --alias=<name> After installing, set the alias specified to the version specified. (same as: nvm alias <name> <version>) --default After installing, set default alias to the version specified. (same as: nvm alias default <version>) nvm uninstall <version> Uninstall a version nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available. nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available. nvm use [<version>] Modify PATH to use <version>. Uses .nvmrc if available and version is omitted. The following optional arguments, if provided, must appear directly after `nvm use`: --silent Silences stdout/stderr output --lts Uses automatic LTS (long-term support) alias `lts/*`, if available. --lts=<LTS name> Uses automatic alias for provided LTS line, if available. nvm exec [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available and version is omitted. The following optional arguments, if provided, must appear directly after `nvm exec`: --silent Silences stdout/stderr output --lts Uses automatic LTS (long-term support) alias `lts/*`, if available. --lts=<LTS name> Uses automatic alias for provided LTS line, if available. nvm run [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available and version is omitted. The following optional arguments, if provided, must appear directly after `nvm run`: --silent Silences stdout/stderr output --lts Uses automatic LTS (long-term support) alias `lts/*`, if available. --lts=<LTS name> Uses automatic alias for provided LTS line, if available. nvm current Display currently activated version of Node nvm ls [<version>] List installed versions, matching a given <version> if provided --no-colors Suppress colored output --no-alias Suppress `nvm alias` output nvm ls-remote [<version>] List remote versions available for install, matching a given <version> if provided --lts When listing, only show LTS (long-term support) versions --lts=<LTS name> When listing, only show versions for a specific LTS line --no-colors Suppress colored output nvm version <version> Resolve the given description to a single local version nvm version-remote <version> Resolve the given description to a single remote version --lts When listing, only select from LTS (long-term support) versions --lts=<LTS name> When listing, only select from versions for a specific LTS line nvm deactivate Undo effects of `nvm` on current shell --silent Silences stdout/stderr output nvm alias [<pattern>] Show all aliases beginning with <pattern> --no-colors Suppress colored output nvm alias <name> <version> Set an alias named <name> pointing to <version> nvm unalias <name> Deletes the alias named <name> nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version nvm unload Unload `nvm` from shell nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available and version is omitted. --silent Silences stdout/stderr output when a version is omitted nvm cache dir Display path to the cache directory for nvm nvm cache clear Empty cache directory for nvm nvm set-colors [<color codes>] Set five text colors using format "yMeBg". Available when supported. Initial colors are: bygre Color codes: r/R = red / bold red g/G = green / bold green b/B = blue / bold blue c/C = cyan / bold cyan m/M = magenta / bold magenta y/Y = yellow / bold yellow k/K = black / bold black e/W = light grey / white Example: nvm install 8.0.0 Install a specific version number nvm use 8.0 Use the latest available 8.0.x release nvm run 6.10.3 app.js Run app.js using node 6.10.3 nvm exec 4.8.3 node app.js Run `node app.js` with the PATH pointing to node 4.8.3 nvm alias default 8.1.0 Set default node version on a shell nvm alias default node Always default to the latest available node version on a shell nvm install node Install the latest available version nvm use node Use the latest version nvm install --lts Install the latest LTS version nvm use --lts Use the latest LTS version nvm set-colors cgYmW Set text colors to cyan, green, bold yellow, magenta, and white Note: to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)
用 nvm ls-remote
查詢一下目前可安裝的 Node.js 版本:
$ nvm ls-remote ...... v20.9.0 (LTS: Iron) v20.10.0 (LTS: Iron) v20.11.0 (Latest LTS: Iron) v21.0.0 v21.1.0 v21.2.0 v21.3.0 v21.4.0 v21.5.0 v21.6.0 v21.6.1
來安裝 v2011.0 這個目前最新的 LTS 版本:
nvm install v20.11.0
用 nvm ls
看一下目前安裝好的版本:
$ nvm ls -> v20.11.0 system default -> v20.11.0 iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v20.11.0) (default) stable -> 20.11 (-> v20.11.0) (default) lts/* -> lts/iron (-> v20.11.0) 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.19.0 (-> N/A) lts/iron -> v20.11.0
用 nvm use
指定現在要使用的 Node.js 版本:
nvm use v20.11.0
現在就可以正確的安裝 n8n 了:
$ npx n8n Initializing n8n process n8n ready on 0.0.0.0, port 5678 ...... Version: 1.26.0 Editor is now accessible via: http://localhost:5678/ Press "o" to open in Browser. Owner was set up successfully User survey updated successfully
(本頁面已被瀏覽過 229 次)