Node.js
用 fnm 安装和切换 Node.js。它和 nvm 的用途相同,安装和切换更快。
安装 fnm
fnm 常用命令
bash
# 切换 Node.js 版本
fnm use <version>
# 列出已安装的 Node.js 版本
fnm list
# 列出可安装的 Node.js 版本
fnm list remote
# 安装指定版本的 Node.js
fnm install <version>
# 卸载指定版本的 Node.js
fnm uninstall <version>
# 设置默认 Node.js 版本
fnm default <version>
# 显示当前使用的 Node.js 版本
fnm current
# 显示 fnm 的帮助信息
fnm help
# 显示 fnm 的版本信息
fnm --version
--use-on-cd会在进入目录时读取该目录要求的 Node.js 版本。
macOS
bash
brew install fnm写入 ~/.zshrc:
由于有 echo,需要在 Powerlevel10k 之前配置输出,否则会警告。
bash
eval "$(fnm env --use-on-cd --shell zsh)"Ubuntu
bash
curl -fsSL https://fnm.vercel.app/install | bash写入 ~/.bashrc:
bash
eval "$(fnm env --use-on-cd --shell bash)"国内加速:
bash
curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/Schniz/fnm/refs/heads/master/.ci/install.sh | bashWindows
- 下载 fnm,并解压。
- 在用户环境变量
Path中添加 fnm 的实际解压目录
PowerShell:
powershell
if (-not (Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }
notepad $PROFILEpowershell
fnm env --use-on-cd --shell powershell | Out-String | Invoke-ExpressionGit Bash,写入 ~/.bashrc:
bash
eval "$(fnm env --use-on-cd --shell bash)"