yarn安装

macOS

Homebrew

你可以通过 Homebrew 包管理工具 安装 Yarn。 如果你还未安装 Node.js,Homebrew 会自动为你安装。

brew install yarn

如果你用的是 nvm 或类似工具,你需要确保 PATH 变量中列出的 nvm 版本的路径在 Homebrew 安装的 Node.js 路径之前。

MacPorts

你可以通过 MacPorts 安装 Yarn 。 如果你还未安装 Node.MacPorts 会自动为你安装。

sudo port install yarn

Installation Script

One of the easiest ways to install Yarn on macOS and generic Unix environments is via our shell script. You can install Yarn by running the following code in your terminal:

curl -o- -L https://yarnpkg.com/install.sh | bash

The installation process includes verifying a GPG signature. View the source on GitHub

You can also specify a version by running the following code in your terminal:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]

See the releases for possible versions.

Manual Install via tarball

You can install Yarn by downloading a tarball and extracting it anywhere.

cd /opt
wget https://yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/

Before extracting Yarn, it is recommended that you verify the tarball using GPG:

wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for "Good signature from 'Yarn Packaging'" in the output

路径设置

如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。

注意:您的配置文件可能是 .profile.bash_profile.bashrc.zshrc 等。

  1. 将此项加入您的配置文件: export PATH="$PATH:/opt/yarn-[version]/bin" (路径可能根据您安装 Yarn 的位置而有差异)
  2. 在终端中,执行登录并登出以使更改生效

为了可以全局访问 Yarn 的可执行文件,你需要在控制台(或命令行)中设置 PATH 环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`" 到你的配置文件中,或者,如果你使用的是 Fish shell,直接执行此命令 set -U fish_user_paths (yarn global bin) $fish_user_paths 即可。

升级 Yarn

有新版时,Yarn 会给你提示。 如需升级 Yarn ,仍然可以通过 Homebrew 来升级。

brew upgrade yarn

通过如下命令测试 Yarn 是否安装成功:

yarn --version
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

优价实习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值