前言
最近搭建需要安装yarn,默认sudo apt-get install yarn安装失败
![](https://img-blog.csdnimg.cn/img_convert/a980732cc60d81a49b7dadd58a53420b.png)
显示本地库中没有yarn安装包
前置条件
需要优先安装nodejs,推荐安装14.x版本
此处优先安装nodejs的版本是由于如果只先安装yarn,会出现
【cli.js 报错】SyntaxError: Unexpected token {
如
sudo yarn --version
usr/share/yarn/lib/cli.js:46288
let {
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/share/yarn/bin/yarn.js:24:13)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
![](https://img-blog.csdnimg.cn/img_convert/ff47aabee0e1fc5f24d20db122ec7b4e.png)
在安装nodejs版本,推荐使用了14.x,如果14.x不成功 可以使用其他版本
安装nodejs
1、curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
![](https://img-blog.csdnimg.cn/img_convert/4e448b07513cbac7695a63fefd330e8b.png)
2、sudo apt-get install -y nodejs
![](https://img-blog.csdnimg.cn/img_convert/3d6b52ef00918b4aaa5582ee509dbe8d.png)
正式安装yarn
curl -sS 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 update
sudo apt install yarn
![](https://img-blog.csdnimg.cn/img_convert/545e66618b1bf64affe30e3b86a9abce.png)
完成安装后
sudo yarn --version查看yarn版本,显示
![](https://img-blog.csdnimg.cn/img_convert/3b5fa5b321cb743967e4cc8c41a7e23a.png)