Yarn 全局命令不起作用

2022-08-30 01:50:56

我正在使用 Yarn v0.16.1。如果我理解正确(根据文档),应该等同于.但是,当我在 docs (with ) 中运行示例时,该命令运行成功,但随后无法从命令行获得。下面是输出:yarn global add <package>npm install -g <package>create-react-appcreate-react-app

$ yarn global add create-react-app
$ yarn global v0.16.1
[1/4] 						

答案 1

You should add export PATH="$PATH:$(yarn global bin)" to your ~/.bash_profile or whatever you use. It would solve the issue.

Depending on how you installed it, Yarn's global folder varies for some reason. You can follow this issue here.


答案 2

Update Dec 2018

Just updating the path didn't work for me. I had to also set the yarn prefix.

  • Ubuntu 18.04.1 LTS (bionic)
  • yarn 1.12.3
  • npm v3.5.2
  • node v8.10.0
  • zsh 5.4.2

Steps

  1. Confirm your global bin path

    yarn global bin
    

I got: /home/username/.yarn/bin

  1. set yarn prefix:

    make sure your yarn prefix is the parent directory of your bin directory. You can confirm by running

    yarn config get prefix
    

    when I ran this, my prefix was empty, so I set it:

    yarn config set prefix ~/.yarn
    
  2. add the following to ~/.bash_profile or ~/.bashrc

    export PATH="$PATH:`yarn global bin`"
    

    for zsh users, be sure to add this line to ~/.zshrc

  3. restart your shell or start a new one

    bash -l or zsh