Linux系统如何安装node管理器

飒爽师叔2020-05-03Linux小知识CentosUbuntuNodenpm
  1. 安装github
yum install git -y # (Centos)
apt install git # (Ubuntu)
  1. 安装node.js管理器等组件
git clone https://github.com/creationix/nvm.git ~/nvm
# 设置nvm 自动运行
echo "source ~/nvm/nvm.sh" >> ~/.bashrc
source ~/.bashrc
# 查看所有版本(部分环境可能不支持最高版本)
nvm list-remote
# 安装npm的最新版本
nvm install stable
# 使用最新版本
nvm use stable

使用国内镜像

  • 对于国内而言,访问外网是很困难的,这会导致访问速度很慢,而国内镜像就很重要了

node 国内镜像

export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node

npm 国内镜像

npm config set registry https://registry.npmmirror.com

npm WIN 国内镜像源

npm config set registry https://registry.npmmirror.com --global
npm config set disturl https://npmmirror.com/mirrors/node --global

yarn 安装

启用yarn

Node.js >=16.10

corepack enable

Node.js <16.10

npm i -g corepack

安装 yarn

corepack prepare yarn@stable --activate
# 指定版本安装yarn
corepack prepare yarn@<version> --activate
最后更新时间 6/1/2024, 3:48:32 PM