6

Node系列 | Node版本管理工具 fnm - Tinywan

 1 year ago
source link: https://www.cnblogs.com/tinywan/p/17427227.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Node系列 | Node版本管理工具 fnm

fnm(Fast Node Manager)基于 Rust 开发,同时,它是跨平台的,支持 macOS、Linux、Windows。🚀 Fast and simple Node.js version manager, built in Rust.

第一种方式:wsl安装

# 初始安装
curl -fsSL https://fnm.vercel.app/install | bash
# 后续升级
curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell
# ~/.zshrc 修改
# 支持自动根据项目 .nvmrc 文件自动切换版本,使用镜像避免可能存在的 fnm install 问题
- eval "$(fnm env)"
+ eval "$(fnm env --use-on-cd --node-dist-mirror=https://repo.huaweicloud.com/nodejs/)"

 第二种方式:直接下载安装

1、下载 fnm.exe,放入 D 盘 D:\fnm,将其目录加入环境变量 path 中

1021265-20230524100026549-220589525.png

 2. 使用 powershell 来执行 fnm 命令

1021265-20230524100059745-1395212491.png

 3. 将以下内容添加到配置文件的末尾

fnm env --use-on-cd | Out-String | Invoke-Expression

用 fnm 安装 Node

# 安装 LTS 版本
$ fnm install --lts

# 安装指定大版本的最新版本
$ fnm install 18

# 安装指定版本
$ fnm install 18.21.1

相反地,可通过 fnm uninstall <version> 或 fnm uninstall <alias-name> 来删除指定版本,后者会同时移除别名。

通过 fnm 来指定 Node 版本  

# 使用系统版本
$ fnm use system

# 使用 fnm 所安装,且版本号为 18.21.1 的 Node 程序
$ fnm use 18.21.1

# 使用 fnm 所安装,且主版本号为 18 的最新版本的 Node 程序
$ fnm use 18

只要用 fnm use <version> 指定后,每次启动 Shell 将会默认使用对应的 Node 版本。

设置别名

# 形式如:fnm alias <指定版本号> <别名>
$ fnm alias 18.21.1 v18

# 设置别名后,可以简化指令为:
$ fnm use v18

常用命令

# 命令帮助
fnm --help

# node 已安装列表
fnm list

# node 安装
fnm install 版本号(支持模糊/lts)

# node 卸载
fnm uninstall 版本号

# node 切换
fnm use 版本号

# node 设置默认
fnm default 版本号
1021265-20230524100616428-2082654171.png

作者:Tinywan

本文版权归作者和博客园共有。欢迎转载,但必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

欢迎关注个人微信公众号,一起进步!扫描左方二维码即可


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK