14

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.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
vikramvi
  • 3,312
  • 10
  • 45
  • 68

8 Answers8

7

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

Solomon Sunday
  • 176
  • 1
  • 6
7

Execute this on your Mac command line:

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

This will set the NPM PATH DIRECTORY

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Dan George
  • 105
  • 1
  • 2
5

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 :)

ullas kunder
  • 384
  • 4
  • 11
2

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

$nodenv rehash

after that yarn should work

mahatmanich
  • 10,791
  • 5
  • 63
  • 82
2

Per this Yarn Installation guide "The preferred way to manage Yarn is through Corepack, a new binary shipped with all Node.js releases starting from 16.10."

As of 2023 - on a Mac - for Node.js >=16.10 - this worked for me after updating node to 16.17:

corepack enable
Norbert Ryan
  • 51
  • 1
  • 4
  • 2 days troubleshooting this on Mac M1. Yarn "segmentation fault" in VSCode terminal, but regular Mac terminal was fine. Followed this suggestion (use the link above for details) and finally fixed! – Oprimus Aug 10 '23 at 20:21
1

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).

nydame
  • 324
  • 4
  • 8
1

You may try:

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc

if you have installed yarn via homebrew.

saran
  • 356
  • 1
  • 3
  • 14
0

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.

Ti Hausmann
  • 926
  • 8
  • 21