前言
最近搭建需要安装yarn,默认sudo apt-get install yarn安装失败
![](https://i-blog.csdnimg.cn/blog_migrate/f2f8fd71c8aa12a57ef26877c8a3732e.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://i-blog.csdnimg.cn/blog_migrate/aab70f067c1b1786b4fa093217ed368c.png)
在安装nodejs版本,推荐使用了14.x,如果14.x不成功 可以使用其他版本
安装nodejs
1、curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
![](https://i-blog.csdnimg.cn/blog_migrate/a19ea3cfa9fd7c13ea528c03e7686e53.png)
2、sudo apt-get install -y nodejs
![](https://i-blog.csdnimg.cn/blog_migrate/04c18661a1b30126e91b3ca6dccc6277.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://i-blog.csdnimg.cn/blog_migrate/c76c1643b47d991101185fe47275fa35.png)
完成安装后
sudo yarn --version查看yarn版本,显示
![](https://i-blog.csdnimg.cn/blog_migrate/54d1dc8182cd21d8fd1e9aae587ddae0.png)