安装多个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
相关推荐
Q_Q196328847537 分钟前
python+uniapp基于微信小程序的助眠小程序
spring boot·python·小程序·django·flask·uni-app·node.js
孟陬1 小时前
事件驱动 vs 轮询:为什么 Node.js 官方推荐 `fs.watch()` 而非 `fs.watchFile`
node.js
林希_Rachel_傻希希3 小时前
Express 入门全指南:从 0 搭建你的第一个 Node Web 服务器
前端·后端·node.js
Q_Q51100828517 小时前
python+uniapp基于微信小程序团购系统
spring boot·python·微信小程序·django·uni-app·node.js·php
云枫晖1 天前
深入浅出npm:现代JavaScript项目基石
前端·javascript·node.js
Q_Q19632884751 天前
python+vue的在线租房 房屋租赁系统
开发语言·vue.js·spring boot·python·django·flask·node.js
不会写DN1 天前
用户头像文件存储功能是如何实现的?
java·linux·后端·golang·node.js·github
前端双越老师1 天前
译: 构建高效 AI Agent 智能体
前端·node.js·agent
哆啦A梦15882 天前
搜索页面布局
前端·vue.js·node.js
Q_Q5110082852 天前
python+uniapp基于微信小程序的旅游信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js