'Why doesn't my 'npm install --global yarn' work?

After running npm install --global yarn, I get an output that says:

> [email protected] preinstall C:\Users\(me)\AppData\Roaming\npm\node_modules\yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)

C:\Users\(me)\AppData\Roaming\npm\yarn -> C:\Users\(me)\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js
C:\Users\(me)\AppData\Roaming\npm\yarnpkg -> C:\Users\(me)\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js
+ [email protected]
updated 1 package in 0.389s

When I run "yarn serve" it tells me that 'yarn' is not recognized as a command. I've tried this in powershell and CMD and neither works.



Solution 1:[1]

It ended up being a path issue. I used npm list -g to reveal where yarn was installed. Then I searched for "Edit the environment variables" in Windows and added the containing folder to the PATH.

I also updated my node and npm to the latest versions before doing these steps.

Solution 2:[2]

Just put --> npm install -g yarn

The problem is that you're installing nvm as root, and when npm runs the lifecycle scripts it downgrades the permissions, making it impossible to even run Node scripts, since the node binary can only be accessed by root.

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 fordat
Solution 2 Tyler2P