安装多个nodejs版本(nvm)

一 安装nvm(Node Version Manager)

安装包已上传


二 安装nodejs

使用nvm install <版本号> 可能会安装失败,需要手动下载
nodejs下载地址

解压后放到nvm目录中

三 npm 设置国内镜像加速

使用国内的 npm 镜像可以显著提升包的下载速度,尤其是在中国大陆地区。以下是几种常见的方法来设置 npm 使用国内镜像。

1. 使用 cnpm

cnpm 是由淘宝提供的 npm 镜像客户端,可以直接替代 npm。安装 cnpm 后,你可以使用 cnpm 命令来代替 npm

安装 cnpm
bash 复制代码
npm install -g cnpm --registry=https://registry.npmmirror.com
使用 cnpm

安装完成后,你可以使用 cnpm 命令来安装包:

bash 复制代码
cnpm install <package-name>

2. 修改 npm 配置

你也可以直接修改 npm 的配置,使其使用国内的镜像源。

临时使用

在每次安装包时指定镜像源:

bash 复制代码
npm install <package-name> --registry=https://registry.npmmirror.com
永久设置

将镜像源永久设置为国内镜像:

bash 复制代码
npm config set registry https://registry.npmmirror.com

3. 使用 nrm(NPM Registry Manager)

nrm 是一个 npm 镜像源管理工具,可以帮助你轻松切换不同的镜像源。

安装 nrm
bash 复制代码
npm install -g nrm
查看可用的镜像源
bash 复制代码
nrm ls

输出示例:

复制代码
  npm ---- https://registry.npmjs.org/
  yarn --- https://registry.yarnpkg.com/
  taobao - https://registry.npmmirror.com/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  cnpm --- http://r.cnpmjs.org/
切换镜像源
bash 复制代码
nrm use taobao

4. 验证设置

你可以通过以下命令验证当前使用的镜像源:

bash 复制代码
npm config get registry

输出应该显示为你设置的镜像源地址,例如:

复制代码
https://registry.npmmirror.com
相关推荐
会飞的鱼先生10 小时前
Node.js-path模块
node.js
企鹅侠客13 小时前
实践篇:14-构建 Node.js 应用程序镜像
docker·node.js·dockerfile
爱分享的程序员15 小时前
前端面试专栏-算法篇:18. 查找算法(二分查找、哈希查找)
前端·javascript·node.js
YongGit17 小时前
探索 AI + MCP 渲染前端 UI
前端·后端·node.js
ncj39343790620 小时前
vscode中对node项目进行断点调试
vscode·node.js
abigale0321 小时前
webpack+vite前端构建工具 -11实战中的配置技巧
前端·webpack·node.js
墨菲安全1 天前
NPM组件 betsson 等窃取主机敏感信息
前端·npm·node.js·软件供应链安全·主机信息窃取·npm组件投毒
csdn_aspnet2 天前
Node.js 使用 WebSockets 和 Socket.IO 实现实时聊天应用程序
node.js
whhhhhhhhhw2 天前
Node.js核心API(fs篇)
node.js
聪聪的学习笔记2 天前
【1】确认安装 Node.js 和 npm版本号
前端·npm·node.js