安装多个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
相关推荐
YIAN1 天前
RAG 学到最后,我真正学会的不是“检索”,而是让系统知道自己缺什么
langchain·node.js·llm
用户11977079480731 天前
GitHub 电商开源项目分享:用 sharp 批量出饰品主图,试了裁剪、细节图和色彩配置文件三个坑
前端·node.js
donecoding1 天前
pnpm 配好了,为什么执行的还是另一份?命令入口与运行时排查
node.js·前端工程化
江屿风1 天前
【Plain Language Large Model】【从浏览器到全栈:一课精通Node.js三剑客】流食般投喂
笔记·前端框架·npm·node.js·js·npx
SomeOtherTime1 天前
node.js基础(AI回答)
node.js
雨季mo浅忆2 天前
记录Node.js安全漏洞及其内置Brotli解码器问题
node.js·安全性测试
tommyjiatong2 天前
资安底座连环雷:从 PHP2Shell 到 Node2Shell
node.js·php
SEO_juper2 天前
Bash 交叉验证 robots.txt 和 sitemap:两个文件自相矛盾,页面永远收录不了
开发语言·python·node.js·json·bash
SEO_juper2 天前
Go 站点地图生成器:从首页爬全站,一键生成 sitemap.xml
xml·开发语言·人工智能·golang·node.js·seo·外贸独立站
Moshow郑锴3 天前
Ansible 批量部署 Node.js 服务:ZIP 直解与共享目录分发两种方案对比
node.js·ansible