溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Node.js怎么進(jìn)行版本管理

發(fā)布時(shí)間:2022-08-11 09:36:59 來(lái)源:億速云 閱讀:424 作者:iii 欄目:web開(kāi)發(fā)

這篇文章主要介紹“Node.js怎么進(jìn)行版本管理”,在日常操作中,相信很多人在Node.js怎么進(jìn)行版本管理問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Node.js怎么進(jìn)行版本管理”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

Node.js怎么進(jìn)行版本管理

1. nvm

? Github stars: 60K+

nvm 是一款 Node.js 版本管理工具,允許用戶通過(guò)命令行快速安裝、切換和管理不同的 Node.js 版本。

Node.js怎么進(jìn)行版本管理

nvm 只適用于 macOS 和 Linux 用戶的項(xiàng)目,如果是 Windows 用戶,可以使用 nvm-windows 、nodist 或 nvs 替換。

安裝方式

macOS 下載方式:

# 方式1 瀏覽器打開(kāi)下面鏈接下載
https://github.com/nvm-sh/nvm/blob/v0.39.1/install.sh
# 下載完成后,通過(guò)命令安裝
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

安裝過(guò)程中如果遇到一些奇怪的問(wèn)題,可以查看下 nvm 補(bǔ)充說(shuō)明。

常用命令

nvm ls                # 查看版本安裝所有版本
nvm ls-remote         # 查看遠(yuǎn)程所有的 Node.js 版本
nvm install 17.0.0    # 安裝指定的 Node.js 版本
nvm use 17.0.0        # 使用指定的 Node.js 版本
nvm alias default 17.0.0  # 設(shè)置默認(rèn) Node.js 版本
nvm alias dev 17.0.0  # 設(shè)置指定版本的別名,如將 17.0.0 版本別名設(shè)置為 dev

Node.js怎么進(jìn)行版本管理

2. n

? Github stars: 16.7K+

n 是一款交互式的 Node.js 版本管理工具,沒(méi)有子腳本,沒(méi)有配置文件,也沒(méi)有復(fù)雜的 API,使用起來(lái)非常簡(jiǎn)單。

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

安裝方式

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

npm install n -g

常用命令

n          # 顯示所有已下載版本
n 10.16.0  # 下載指定版本
n lts      # 查看遠(yuǎn)程所有 LTS Node.js 版本
n run 10.16.0 # 運(yùn)行指定的 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 <version>                    Install Node.js <version> (downloading if necessary)
  n install <version>            Install Node.js <version> (downloading if necessary)
  n run <version> [args ...]     Execute downloaded Node.js <version> with [args ...]
  n which <version>              Output path for downloaded node <version>
  n exec <vers> <cmd> [args...]  Execute command with modified PATH, so downloaded node <version> and npm first
  n rm <version ...>             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 是一款快速簡(jiǎn)單 ? 的 Node.js 版本管理器,使用 Rust 構(gòu)建。

Node.js怎么進(jìn)行版本管理

主要特點(diǎn)包括:

  • 跨平臺(tái)支持,包括:macOS、Windows、Linux;

  • 單一文件,輕松安裝,即時(shí)啟動(dòng) ;

  • 以速度為設(shè)計(jì)理念;

  • 適用于 .node-version.nvmrc 文件。

安裝方式

macOS / Linux 環(huán)境:

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

Windows 環(huán)境:

# 管理員模式打開(kāi)終端,安裝后只能使用管理員模式打開(kāi)使用

choco install fnm

# 安裝完成還需要手動(dòng)設(shè)置環(huán)境變量

Linux/macOS/Windows 環(huán)境也可以直接下載二進(jìn)制文件安裝

常用命令

fnm -h             # 查看幫助
fnm install 17.0.0 # 安裝指定 Node.js 版本
fnm use 17.0.0     # 使用指定 Node.js 版本
fnm default 17.0.0 # 設(shè)置默認(rèn) Node.js 版本

到此,關(guān)于“Node.js怎么進(jìn)行版本管理”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI