'-bash: yarn: command not found even after installing it globally

Mac OS 10.13.6

How did I install yarn

npm install --global yarn

yarn installation path is /Users/useName/.config/yarn

Then ran below command

yarn create react-app app-name

This worked well, but when I'm trying to run yarn add package_name, it's throwing error

bash: yarn: command not found

The weird thing, after closing and opening terminal again under which I had globally ( ? ) installed yarn, the yarn command is not found.



Solution 1:[1]

try export PATH=~/.yarn/bin:$PATH into .profile !**

or

try: If you are on the bash try adding alias yarn=~/.yarn/bin/yarn.js

We no longer support global installation of Create React App.

Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app

The latest instructions for creating a new app can be found here:

create-react-app.dev/docs/getting-started

@github ;)

Try this Stackoverflow :)

Solution 2:[2]

If you are using nodenv and yarn is not working try a simple

$nodenv rehash

after that yarn should work

Solution 3:[3]

Execute this on your Mac command line:

export PATH=~/.npm-global/bin:$PATH.

This will set the NPM PATH DIRECTORY

Solution 4:[4]

Global packages won't be installed in a user account. The path you mention is for configuration. Try to find where Yarn was really installed or just try export PATH=/usr/local/bin:$PATH (that's where Yarn is on my machine).

Solution 5:[5]

After npm i -g yarn I had to manually add npm packages to my $PATH. Adding these two lines to my ~/.profile fixed it, after restarting the Terminal the yarn command became available:

NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$NPM_PACKAGES/bin:$PATH"

I found them in my ~/.bashrc but somehow it was not executed.

Solution 6:[6]

Just re- install using "brew install yarn" and that should solve it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 mahatmanich
Solution 3 Jeremy Caney
Solution 4 nydame
Solution 5
Solution 6 Solomon Sunday