fnm install 命令詳解
fnm install 命令用於安裝新的 Node.js 版本。
命令語法
bash
fnm install [OPTIONS] [VERSION]參數說明
VERSION
指定要安裝的 Node.js 版本:
bash
# 安裝主版本(自動選擇最新次版本)
fnm install 20
# 安裝特定版本
fnm install 20.10.0
# 安裝 LTS 版本
fnm install lts/iron
# 不指定版本,讀取版本文件
fnm install選項說明
--lts
安裝最新的 LTS(長期支持)版本:
bash
fnm install --lts--latest
安裝最新版本(包括非 LTS):
bash
fnm install --latest--use
安裝後立即切換到該版本:
bash
fnm install 20 --use--progress
控制下載進度條顯示:
bash
# 自動顯示(默認)
fnm install 20 --progress=auto
# 始終顯示
fnm install 20 --progress=always
# 從不顯示
fnm install 20 --progress=never--node-dist-mirror
指定 Node.js 下載鏡像:
bash
fnm install 20 --node-dist-mirror=https://npmmirror.com/mirrors/node--arch
指定安裝的架構:
bash
# 安裝 x64 版本
fnm install 20 --arch=x64
# 安裝 ARM64 版本
fnm install 20 --arch=arm64--fnm-dir
指定 fnm 安裝目錄:
bash
fnm install 20 --fnm-dir=/custom/path--log-level
設置日志級別:
bash
fnm install 20 --log-level=quiet
fnm install 20 --log-level=error
fnm install 20 --log-level=info--corepack-enabled
啟用 Corepack 支持:
bash
fnm install 20 --corepack-enabled使用示例
安裝 LTS 版本
bash
# 安裝最新 LTS
fnm install --lts
# 安裝指定 LTS 版本
fnm install lts/iron # Node.js 20.x
fnm install lts/hydrogen # Node.js 18.x安裝特定版本
bash
# 安裝主版本
fnm install 20
# 安裝次版本
fnm install 20.10
# 安裝精確版本
fnm install 20.10.0安裝並使用
bash
# 安裝並立即切換
fnm install 20 --use
# 安裝並設置為默認
fnm install 20 --use && fnm default 20使用鏡像加速
bash
# 使用國內鏡像
fnm install 20 --node-dist-mirror=https://npmmirror.com/mirrors/node安裝特定架構
bash
# 在 Apple Silicon Mac 上安裝 x64 版本
fnm install 20 --arch=x64版本格式
fnm 支持多種版本格式:
| 格式 | 示例 | 說明 |
|---|---|---|
| 主版本 | 20 | 最新的 20.x.x |
| 次版本 | 20.10 | 最新的 20.10.x |
| 精確版本 | 20.10.0 | 精確版本 |
| LTS 名稱 | lts/iron | LTS 版本代號 |
| latest | --latest | 最新版本 |
LTS 版本代號
| 代號 | 版本 | 發布日期 |
|---|---|---|
| Iron | 20.x | 2023-10 |
| Hydrogen | 18.x | 2022-10 |
| Gallium | 16.x | 2021-10 |
| Erbium | 14.x | 2020-10 |
| Dubnium | 12.x | 2019-10 |
環境變量
可以通過環境變量配置默認行為:
bash
# 設置鏡像
export FNM_NODE_DIST_MIRROR=https://npmmirror.com/mirrors/node
# 啟用 Corepack
export FNM_COREPACK_ENABLED=true
# 設置安裝目錄
export FNM_DIR=~/.fnm常見問題
安裝失敗
bash
# 嘗試使用鏡像
fnm install 20 --node-dist-mirror=https://npmmirror.com/mirrors/node
# 查看詳細日志
fnm install 20 --log-level=info版本已存在
bash
# 查看已安裝版本
fnm list
# 使用已安裝版本
fnm use 20下載慢
bash
# 配置鏡像
export FNM_NODE_DIST_MIRROR=https://npmmirror.com/mirrors/node
fnm install 20相關鏈接
- 安裝 Node.js - 安裝指南
- 命令參考 - 所有命令詳解
- 下載管理 - 下載配置