fnm(node版本管理工具)

1,714 阅读1分钟

支持Windows,Mac,Linux。

安装fnm

  1. 下载fnm。我选择下载.exe执行文件

github.com/Schniz/fnm/…

  1. 配置环境变量

FNM_DIR:配置以后安装的node各个版本的目录, 并且每个版本的全局安装的包也会在这个目录下,如果不配置的话, 会默认安装在C:\Users{your user name}\AppData\Roaming\fnm下。

配置path,添加 fnm.exe存放的位置

  1. 在powershell的 profile中添加fnm env --use-on-cd | Out-String | Invoke-Expression
# Environment variables need to be setup before you can start using fnm. This is done by evaluating the output of fnm env. To automatically run fnm use when a directory contains a .node-version or .nvmrc file, add the --use-on-cd option to your shell setup.
# --use-on-cd参数表示当目录切换时自动调用该配置,以便自动切换Node版本。
# 当文件夹中有 .node-version or .nvmrc file ,自动执行 fnm use ,所以终端会自动显示当前目录的node版本
fnm env --use-on-cd | Out-String | Invoke-Expression

移除fnm

Removing

To remove fnm (😢), just delete the .fnm folder in your home directory. You should also edit your shell configuration to remove any references to fnm (ie. read Shell Setup, and do the opposite).

参考

fnm + Cmder使用, 从此不再有多个项目多个Node切来切去的苦恼了[windows] - 掘金 (juejin.cn)