ubuntu18安装yarn、安装vue

335 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

Updated@2022-03-04

The acticle is out of date, try this instead:

yarn安装和配置国内源_jaket5219999的博客-CSDN博客_yarn配置国内


Updated at 2020-03-11

sudo apt update
sudo apt install nodejs
sudo apt install npm
sudo npm i -g npm --registry https://registry.npm.taobao.org
sudo npm i -g yarn --registry https://registry.npm.taobao.org
yarn config set registry https://registry.npm.taobao.org -g
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
npm config set registry https://registry.npm.taobao.org

------------------------------ Before updated

操作系统为ubuntu18

第一步:换源

sudo python -c "s='mirrors.163.com';
import re;
f=open('/etc/apt/sources.list','r+');
a=f.read();
f.seek(0);
f.truncate();
f.write(re.sub(r'(deb|security)\.debian\.org', s, a));
f.close()"

参考:ubuntu 换源_jaket5219999的博客-CSDN博客

第二步:安装yarn

sudo apt-get update
sudo apt-get upgrade
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-get update
sudo apt-get install yarn

如果用的是nvm,要这样安装:

# sudo apt install --no-install-recommends yarn
yarn --version

参考:How To Install Yarn on Ubuntu 18.04 LTS - idroot

第三步:给yarn换淘宝源

yarn config set registry https://registry.npm.taobao.org

参考:yarn设置淘宝镜像问题 亲测成功_菜菜程序员-CSDN博客_yarn配置镜像仓库

第四步:安装vue

yarn global add @vue/cli

参考:Installation | Vue CLI


如果安装完找不到vue,可用find命令找到vue所在目录,把该目录加给PATH

sudo find / -name "vue"
# /home/vagrant/.yarn/bin/vue
echo '# set PATH for yarn
if [ -d "$HOME/.yarn/bin" ] ; then
    PATH="$HOME/.yarn/bin:$PATH"
fi' >> ~/.profile
. ~/.profile
vue --version
# 3.4.1
“我们都是这个世界上的迷路者,我们都是按照自己认定的道路寻找方向,也许我们是对的,也许我们错了,或者有时候对了,有时候错了。在中国人所说的盖棺论定之前,在古罗马人所说的出生之前和死去之前,我们谁也不知道在前面的时间里等待我们的是什么。”