安装多个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
相关推荐
muddjsv12 小时前
Node.js 开发上手指南:从环境搭建到实战开发
node.js
福大大架构师每日一题13 小时前
dify 1.11.4 正式发布:全面强化安全性、修复多项关键问题,Node.js 升级至 24.13.0!附详细升级指南
node.js·dify
winfredzhang14 小时前
从零构建:基于 Node.js 与 ECharts 的量化交易策略模拟系统
前端·node.js·echarts·股票·策略
Ashley_Amanda15 小时前
Node.js 版本管理指南
node.js
摇滚侠16 小时前
Node.js 安装及环境变量配置,压缩包格式的安装包
node.js
天天打码1 天前
Svelte-无虚拟DOM、极致性能的现代高性能Web开发框架!
前端·node.js·vue·svelte
吹牛不交税2 天前
win10切换node.js版本
node.js
局外人LZ2 天前
Forge:web端与 Node.js 安全开发中的加密与网络通信工具集,支持哈希、对称 / 非对称加密及 TLS 实现
前端·安全·node.js
JaredYe2 天前
node-plantuml-2:革命性的纯Node.js PlantUML渲染器,告别Java依赖!
java·开发语言·node.js·uml·plantuml·jre
南方姑娘-qing2 天前
nodejs脚本部署到服务器自动运行
node.js