Node 版本管理工具 fnm
fnm
Fast and simple Node.js version manager, built in Rust
fnm 是一款快速简单 的 Node.js 版本管理器,使用 Rust 构建。
常用命令
fnm list # 查看已经安装的 Node.js 版本,也可以使用 fnm ls
fnm -h # 查看帮助
fnm install 22.21.1 # 安装指定 Node.js 版本
fnm use 22.21.1 # 使用指定 Node.js 版本
fnm default 22.21.1 # 设置默认 Node.js 版本
fnm list-remote # 查看可以安装的 Node.js 版本
fnm uninstall 22.21.1

下载配置
下载最新版的 fnm-windows.zip :Github下载,蓝奏云备份
下载好,把里面的 fnm.exe 解压缩去你想放置的地方。
这里放在 C:\sw\fnm\fnm.exe ,
然后把上面放置了 fnm.exe 的路径 C:\sw\fnm\ 放在 PATH 上。
验证是否安装配置完成
fnm --version

安装 PowerShell
Github 下载 PowerShell-7.5.4-win-x64.msi
查看版本号
$PSVersionTable
现在使用的是 7.5.4
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Windows 10.0.26200
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PowerShell 中配置 fnm
参考
https://github.com/Schniz/fnm#shell-setup
命令方式
使用命令直接创建配置文件并写入内容
直接执行下面几条命令即可:
# 如果 profile 不存在就创建
if (!(Test-Path $PROFILE)) { New-Item $PROFILE -Force }
# 写入 fnm 初始化配置
Add-Content $PROFILE 'fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression'
# 重新加载 profile
. $PROFILE
验证:
fnm --version
node --version
手动创建配置文件(手动方式)
手动创建或打开 PowerShell profile 文件,路径如下(选你正在用的):
Windows
PowerShell 5:%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PowerShell 6+:%USERPROFILE%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
%USERPROFILE%\Documents\ 表示用户的文档目录
macOS / Linux
~/.config/powershell/Microsoft.PowerShell_profile.ps1
在文件末尾加入一行:
fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
重新加载:
. $PROFILE
验证:
fnm --version
node --version
PowerShell 7.5.4 配置

npm 常用命令
设置镜像
npm config set registry https://registry.npmmirror.com/
npm 常用命令
# 安装依赖包,安装当前项目 package.json 文件中定义的所有依赖包。
npm install
# 安装特定包
npm install <package-name>
# 全局安装包,全局安装某个包,使其在系统的任何地方都可以使用。
npm install -g <package-name>
# 卸载包
npm uninstall <package-name>
# 更新包,更新指定包到最新版本。
npm update <package-name>
# 初始化项目,初始化一个新的 package.json 文件。
npm init
# 运行脚本,运行 package.json 中定义的脚本,例如 npm run build。
npm run <script-name>
# 查看全局安装的包
npm list -g --depth=0
# 查看本地项目中的包,查看当前项目中安装的包。
npm list
# 清理缓存
npm cache clean --force
npm 镜像查看和设置
# 查看当前 npm 镜像仓库的地址
npm config get registry
# 设置 npm 镜像仓库为官方源
npm config set registry https://registry.npmjs.org/
# 设置 npm 镜像仓库为淘宝镜像
npm config set registry https://registry.npmmirror.com/

浙公网安备 33010602011771号