1.介紹
非專業(yè)前端開發(fā)工程師在構建項目時遇到如下問題:
ERROR: This version of pnpm requires at least Node.js v16.14
The current version of Node.js is v14.17.0
Visit https://r.pnpm.io/comp to see the list of past pnpm versions with respective Node.js version support.
懵了,一臺電腦安裝多個JDK版本我們是常遇到的,前端就不知道怎么處理了,幸虧有了nvm
。使用它可以簡單解決上面的問題:
nvm install 16.14.0
nvm
是 Node.js 的版本管理工具(Node Version Manager)。它允許在同一臺計算機上同時安裝和管理多個 Node.js 版本。這對于開發(fā)人員和項目來說是非常有用的,因為不同的項目可能需要不同的 Node.js 版本來運行。以下是 nvm
的一些主要用途:
-
多版本支持: 允許你在同一臺計算機上安裝多個 Node.js 版本,而不會互相干擾。這對于不同項目使用不同的 Node.js 版本時非常重要。
-
版本切換: 允許你在不同項目之間切換 Node.js 版本。通過簡單的命令,你可以輕松切換全局 Node.js 版本或在特定項目目錄中使用特定版本。
-
便于測試: 如果你的應用程序或庫需要在不同版本的 Node.js 上進行測試,
nvm
可以使得這個過程更加簡便。你可以在不同版本的 Node.js 上運行測試套件,確保你的代碼在各個環(huán)境中都能正常工作。 -
升級和回退: 通過
nvm
,你可以輕松升級到最新的 Node.js 版本,或者在需要時回退到舊版本。這對于確保應用程序在新版 Node.js 中正常運行,同時避免可能的兼容性問題非常有幫助。文章來源:http://www.zghlxwxcb.cn/news/detail-767455.html
使用 nvm
,可以通過簡單的命令行操作輕松管理 Node.js 版本,而無需手動下載、安裝或卸載。這對于大多數 Node.js 開發(fā)者來說是一個非常方便的工具。文章來源地址http://www.zghlxwxcb.cn/news/detail-767455.html
2.命令使用
2.1 安裝
- Windows直接下載
nvm-setup.exe
雙擊即可安裝。
C:\Users\Administrator>nvm -v
1.1.10
2.2 查看可用的版本
nvm ls
2.3 安裝指定版本的 Node.js
nvm install 16.14.0
2.4切換版本
nvm use 16.14.0
2.5 卸載指定版本的 Node.js
nvm uninstall 14.17.5
2.6 更多命令小伙伴們可以自行探索
Running version 1.1.10.
Usage:
nvm arch : Show if node is running in 32 or 64 bit mode.
nvm current : Display active version.
nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
Add --insecure to the end of this command to bypass SSL validation of the remote download server.
nvm list [available] : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
nvm on : Enable node.js version management.
nvm off : Disable node.js version management.
nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
Set [url] to "none" to remove the proxy.
nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
nvm uninstall <version> : The version must be a specific version.
nvm use [version] [arch] : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
"newest" is the latest installed version. Optionally specify 32/64bit architecture.
nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
nvm root [path] : Set the directory where nvm should store different versions of node.js.
If <path> is not set, the current root will be displayed.
nvm [--]version : Displays the current running version of nvm for Windows. Aliased as v.
3.問題
3.1 無法切換版本
- 原因:安裝nvm時管理的nodejs目錄跟之前安裝的目錄不一致。
- 處理:刪除之前的nodejs目錄,使用nvm重新安裝。
到了這里,關于Node【工具 01】Node Version Manager nvm安裝使用(Node.js版本管理工具)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!