使用nvm(Node Version Manager)安装node及切换版本
nvm是一个非常流行的工具,用于管理和切换Node.js的不同版本。
Github地址为:https://github.com/nvm-sh/nvm
以下是如何安装nvm和切换Node.js版本的步骤:
1.windows下安装nvm
下载地址
Github:https://github.com/coreybutler/nvm-windows/releases
下载后允许安装即可,安装成功后,可打开控制台执行下一步安装node。
2.安装node
打开控制台后,输入nvm可查看支持的所有命令
nvm
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.
查看可安装的node版本
nvm list available
查看所有已安装的Node.js版本,可以使用:
nvm list
使用nvm安装特定版本的Node.js。例如,要安装Node.js 14.x版本,可以使用:
nvm install 14
切换Node.js版本
安装完成后,你可以使用以下命令来切换到不同的Node.js版本:
nvm use 14
设置一个默认的Node.js版本
nvm alias default 14
使用nrm
(npm registry manager)修改npm镜像源
通常情况下,为了加速npm的访问速度,我们可使用nrm工具修改npm镜像地址
1.安装nrm
如果你还没有安装nrm,可以通过npm全局安装:
npm install -g nrm
2.安装完成后,你可以查看当前支持的镜像源:
nrm ls
这将列出所有可用的镜像源及其状态。
如果没有你想使用的镜像源,比如淘宝镜像,则您可以自行手动添加,如果已经存在淘宝镜像,则可跳过该步骤。
nrm add taobao https://registry.npmmirror.com/
3.切换到淘宝镜像
使用以下命令切换到淘宝镜像:
nrm use taobao
4.验证是否切换成功
可以通过以下命令查看当前使用的镜像源:
nrm current