Search code examples
npmzshyarnpkg

I installed yarn globally, but got error "zsh:command not found : yarn"


npm install -g yarn

> yarn@1.22.15 preinstall /Users/myname/.npm-global/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)

/Users/myname/.npm-global/bin/yarn -> /Users/myname/.npm-global/lib/node_modules/yarn/bin/yarn.js
    /Users/myname/.npm-global/bin/yarnpkg -> /Users/myname/.npm-global/lib/node_modules/yarn/bin/yarn.js
    + yarn@1.22.15

As I use a mac, I opened the zshrc file. and then write the code below

export PATH=$PATH:/Users/myname/.npm-global/lib/node_modules/yarn

However, when I entered the yarn --v command, I got the same error as the title.

Could you please tell me what the problem is? What should I do when I have installed a variable globally?


Solution

  • Add the global npm bin to PATH instead:

    export PATH="$PATH:$(npm bin -g)"
    

    In your case, this is the same as:

    export PATH="$PATH:/Users/myname/.npm-global/bin"