Ubuntu安装nodejs和yarn

安装nodejs

nodejs 的每个大版本号都有相对应的源,比如这里的 10.x.x版本的源是https://deb.nodesource.com/setup_10.x。

输入命令:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

接着输入命令:

sudo apt-get install -y nodejs

等待安装完成。

*如果你要安装12.x.x 的版本,只需要修改添加源地址中的数字即可:

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

最后验证:nodejs -v 即可出现安装的nodejs版本。

安装yarn

1、添加GPG密钥

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

2、添加Yarn存储库

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

3、更新包列表并安装Yarn

sudo apt update
sudo apt install yarn

4、检查Yarn的版本

yarn --version