首頁  >  文章  >  web前端  >  Node.js如何進行版本管理? 3款實用版管理工具分享

Node.js如何進行版本管理? 3款實用版管理工具分享

青灯夜游
青灯夜游轉載
2022-08-10 20:20:306970瀏覽

Node如何進行版本管理?以下這篇文章給大家整理分享3 個非常實用的 Node.js 版本管理工具,希望對大家有幫助!

Node.js如何進行版本管理? 3款實用版管理工具分享

在上一篇文章《Node.js各版本間有什麼不同?如何選擇合適的版本? 》中介紹了 Node.js 版本分為 LTS 和 Current 系列,當我們需要在本機開發環境同時安裝 LTS 版本和 Current 版本時,就需要對 Node.js 版本進行版本管理。

例如本機需要同時安裝 Node.js 8.0.0 和 Node.js 17.0.0。

為了能夠對Node.js 版本進行版本管理,我整理了3 個非常實用的Node.js 版本管理工具,讓大家能夠自由的切換本地環境不同的Node. js 版本。

1. nvm

Github stars: 60K

nvm 是一款Node. js 版本管理工具,讓使用者可以透過命令列快速安裝、切換和管理不同的Node.js 版本。

Node.js如何進行版本管理? 3款實用版管理工具分享

圖片來自:github

nvm 只適用於macOS 和Linux 用戶的項目,如果是Windows 用戶,可以使用nvm-windowsnodistnvs 替換。

安裝方式

macOS 下載方式:

# 方式1 浏览器打开下面链接下载
https://github.com/nvm-sh/nvm/blob/v0.39.1/install.sh
# 下载完成后,通过命令安装
sh install.sh

# 方式2 推荐
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# 方式3
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

安裝過程中如果遇到一些奇怪的問題,可以查看下nvm 補充說明

常用指令

nvm ls                # 查看版本安装所有版本
nvm ls-remote         # 查看远程所有的 Node.js 版本
nvm install 17.0.0    # 安装指定的 Node.js 版本
nvm use 17.0.0        # 使用指定的 Node.js 版本
nvm alias default 17.0.0  # 设置默认 Node.js 版本
nvm alias dev 17.0.0  # 设置指定版本的别名,如将 17.0.0 版本别名设置为 dev

Node.js如何進行版本管理? 3款實用版管理工具分享

#2. n

##⭐

Github stars: 16.7K

n 是一款互動式的Node.js 版本管理工具,沒有子腳本,沒有設定文件,也沒有複雜的API,使用起來非常簡單。

Node.js如何進行版本管理? 3款實用版管理工具分享

n 只適用於 macOS 和 Linux ,不適用於 Windows。

安裝方式

可以使用npm 直接安裝到全域:

npm install n -g

常用指令
n          # 显示所有已下载版本
n 10.16.0  # 下载指定版本
n lts      # 查看远程所有 LTS Node.js 版本
n run 10.16.0 # 运行指定的 Node.js 版本

輸入

n -h查看幫助訊息,主要命令如下:

  n                              Display downloaded Node.js versions and install selection
  n latest                       Install the latest Node.js release (downloading if necessary)
  n lts                          Install the latest LTS Node.js release (downloading if necessary)
  n                     Install Node.js  (downloading if necessary)
  n install             Install Node.js  (downloading if necessary)
  n run  [args ...]     Execute downloaded Node.js  with [args ...]
  n which               Output path for downloaded node 
  n exec   [args...]  Execute command with modified PATH, so downloaded node  and npm first
  n rm              Remove the given downloaded version(s)
  n prune                        Remove all downloaded versions except the installed version
  n --latest                     Output the latest Node.js version available
  n --lts                        Output the latest LTS Node.js version available
  n ls                           Output downloaded versions
  n ls-remote [version]          Output matching versions available for download
  n uninstall                    Remove the installed Node.js

#3. fnm

Github stars: 8.4K

fnm 是一款快速簡單? 的Node.js 版本管理器,使用Rust 建置。

Node.js如何進行版本管理? 3款實用版管理工具分享

圖片來自:

freecodecamp

#主要特點包括:

##? 跨平台支持,包括:macOS、Windows、Linux;
  • ✨ 單一文件,輕鬆安裝,即時啟動;
  • ? 以速度為設計理念;
  • ? 適用於
  • .node -version
  • .nvmrc 檔案;
#安裝方式

macOS / Linux 環境:

# bash, zsh and fish shells
curl -fsSL https://fnm.vercel.app/install | bash

Windows 環境:

# 管理员模式打开终端,安装后只能使用管理员模式打开使用

choco install fnm

# 安装完成还需要手动设置环境变量

Linux/macOS/Windows 環境也可以直接下載二進位檔案安裝,下載位址:

github.com/Schniz/fnm/…

#常用指令

fnm -h             # 查看帮助
fnm install 17.0.0 # 安装指定 Node.js 版本
fnm use 17.0.0     # 使用指定 Node.js 版本
fnm default 17.0.0 # 设置默认 Node.js 版本

總結

本文為大家推薦了3 個非常常用的Node.js 版本管理工具,大家可以依照自己實際需求選擇使用。

如果大家有更好的工具,歡迎留言分享。

更多node相關知識,請造訪:nodejs 教學

以上是Node.js如何進行版本管理? 3款實用版管理工具分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:juejin.cn。如有侵權,請聯絡admin@php.cn刪除