目录1. 背景?2. Fast Node Manager (fnm) 2.1. 是什么? 2.2. 安装、使用?
1
. 背景?
有些项目对 Node.js 的版本有要求(例如:codesandbox-client 要求 Node.js 版本要兼容 ^10.22.1),这就需要有一种方法能在你的电脑上管理(安装、切换、删除)多个版本的 Node.js。
2 . Fast Node Manager (fnm)2.1. 是什么?
? Fast and simple Node.js version manager, built in Rust.
? Cross-platform support (Mac, Windows, Linux)
✨ Single file, easy installation, instant startup
? Built with speed in mind
? Works with .node-version and .nvmrc files
注:开源项目 codesandbox-client 即推荐使用 fnm 作为 Node.js 的版本管理器。
2.2. 安装、使用?
工作环境:
OS:Win10
IDE:WebStorm
Terminal:PowerShell
下载发布包、配置PATH环境变量
https://github.com/Schniz/fnm/releases
调整 PowerShell,使它可以正常执行 .ps1 文件(PowerShell脚本文件)
操作系统默认不允许执行 .ps1 文件
set-ExecutionPolicy RemoteSigned
修改 PowerShell 配置文件,在每次启动 PowerShell 时,对 fnm 进行初始化
C:\Users\Administrator\Documents\WindowsPowerShell\profile.ps1
调整 WebStorm 的 Terminal 为 PowerShell
使用 fnm 安装指定版本 Node.js
使用 --node-dist-mirror 加速下载
fnm install v10.22.1 --node-dist-mirror="https://npm.taobao.org/dist"
使用 fnm 切换到指定版本 Node.js
fnm use 10.22.1
顺利切换版本后,即可正常进行后续工作了
参考:
Fast Node Manager (fnm):
https://github.com/Schniz/fnm
PowerShell Execution Policies:
https://docs.microsoft.com/zh-cn/previous-versions/windows/powershell-scripting/hh847748(v=wps.640)
Windows PowerShell Profiles:
https://docs.microsoft.com/en-us/previous-versions//bb613488(v=vs.85)?redirectedfrom=MSDN