【MacOS 一步完成 node、nvm、npm、yarn、pnpm 安装】

MacOS 一步完成 node、nvm、npm、yarn、pnpm 安装

v20.18.1为例

1. 安装流程

  • 安装nvm(Node 版本管理器)
# 安装 nvm (Node 版本管理器)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# 验证环境中是否存在正确的 nvm 版本
nvm -v # 应该打印 `0.40.1`
  • 安装node和npm
# 下载并安装 Node.js(可能需要重启终端)
nvm install 20

# 验证环境中是否存在正确的 Node.js 版本
node -v # 应该打印 `v20.18.1`

# 验证环境中是否存在正确的 npm 版本
npm -v # 应该打印 `10.8.2`
  • 安装yarn
# 下载并安装 yarn(可能需要重启终端)
npm install --global yarn

# 查看版本号
yarn -v
  • 安装pnpm
# 下载并安装 pnpm(可能需要重启终端)
npm install --global pnpm

# 查看版本号
pnpm -v

2. 安装异常或使用问题问题

  • nvm安装问题

安装时出现:Failed to connect to raw.githubusercontent.com port 443: Connection refused
查看解决办法node管理工具nvm在mac上的安装以及失败问题解决

  • nvm切换node版本问题
# 仅对当前终端窗口有效
nvm use [version]

# 当前窗口或新窗口都有效
nvm alias default [version]
  • 配置默认镜像源
# 查询当前npm镜像源
npm get registry
# 设置为淘宝镜像源
npm config set registry https://registry.npmmirror.com
# 还原为官方镜像源
npm config set registry https://registry.npmjs.org


# 查询当前yarn镜像源
yarn config get registry
# 设置为淘宝镜像源
yarn config set registry https://registry.npmmirror.com
# 还原为官方镜像源
yarn config set registry https://registry.yarnpkg.com


# 查询当前pnpm镜像源
pnpm get registry
# 设置为淘宝镜像源
pnpm config set registry https://registry.npmmirror.com
# 还原为官方镜像源
pnpm config set registry https://registry.npmjs.org
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值