8.安装Nodejs和Yarn以及配置国内镜像源(Ubuntu)

1.安装Nodejs

安装依赖和配置nodesource源:

sudo apt-get install curl gcc g++ make
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

配置nodesource源国内镜像:

sudo vim /etc/apt/sources.list.d/nodesource.list

按i进入编辑模式,删除原来的源,替换为如下:

deb https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_14.x focal main
deb-src https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_14.x focal main

esc,输入:wq,按enter确认。

安装Nodejs

sudo apt-get update && sudo apt-get install -y nodejs

配置NPM仓库镜像

#npm仓库淘宝源
npm config set registry https://registry.npm.taobao.org
#npm仓库腾讯云源
npm config set registry http://mirrors.cloud.tencent.com/npm/
#npm仓库华为云源
npm config set registry https://mirrors.huaweicloud.com/repository/npm/

配置node-gyp的依赖python

npm config set python /usr/bin/python3

2.安装Yarn

sudo apt-get install curl gcc g++ make
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
#配置yarn仓库国内镜像源
yarn config set registry https://mirrors.huaweicloud.com/repository/npm/

3.检查当前配置

npm config list
yarn config list

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/basic/js/2104.html

发表评论

邮箱地址不会被公开。 必填项已用*标注