yarn global add no use

Created on 27 Feb 2017  ยท  16Comments  ยท  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

BUG

What is the current behavior?

 ~/Desktop>  yarn global add gitbook-cli
yarn global v0.20.3
warning No license field
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
warning [email protected]: The engine "gitbook" appears to be invalid.
[3/4] ๐Ÿ”—  Linking dependencies...
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Installed "[email protected]" with binaries:
      - gitbook
warning No license field
โœจ  Done in 10.70s.

If the current behavior is a bug, please provide the steps to reproduce.

~/Desktop>  gitbook
zsh: command not found: gitbook

Please mention your node.js, yarn and operating system version.

Yarn v0.20.3
Node v7.6.0 (brew)
OS X 10.12.3

> yarn global bin
/usr/local/Cellar/node/7.6.0/bin

but i found the thing installed at:

~/.config/yarn/global/node_modules/.bin

Most helpful comment

i used to:

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

but now i have to add another one:

export PATH="$PATH:`yarn global bin`:$HOME/.config/yarn/global/node_modules/.bin"

is it a bug of yarn global bin?

All 16 comments

You just need to add ~/.config/yarn/global/node_modules/.bin to your PATH.

i used to:

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

but now i have to add another one:

export PATH="$PATH:`yarn global bin`:$HOME/.config/yarn/global/node_modules/.bin"

is it a bug of yarn global bin?

Not sure but I think it needs some investigation

Looks possibly related to #2807. Note that adding ~/.config/yarn/... to PATH is not a good solution IMO as the root user's home directory is not readable by other users.

I think the idea is that every user has their own global folder.
The good thing is that you don't need sudo to install a global package.
I wonder if there should be a configuration for this

I had not appreciated that yarn global add can be run by non-root user. I think originally I ran yarn global add nodemon without error then tried running nodemon and of course got command not found. Then the 'natural' thing to do is run as root using sudo, which does then install in /usr/bin but in a broken way for non-root users. It's also somewhat confusing that yarn global bin returns /usr/bin for non-root users.

If the intention is for yarn to be purely local to each user, then I guess it shouldn't pollute /usr/bin...? And the instructions should make it clear that people need to modify their PATH.

@jugglingcats the previous version is ok.

and i use os x not linux, my user is administrator.

npm i -g xxx

does not need to add sudo

Two different issues then. I will add my comment to #2807

The same is happening to me:
Node v7.6.0 (brew)
Yarn: v0.21.3 (brew)

@ignacio-air$ l $(yarn global bin)
total 69608
drwxr-xr-x   5 ignacio  staff       170 Mar  6 10:00 .
drwxr-xr-x  10 ignacio  staff       340 Feb 28 20:23 ..
-rwxr-xr-x   1 ignacio  staff  35629284 Feb 21 19:51 node
lrwxr-xr-x   1 ignacio  staff        40 Mar  6 10:00 now -> ../lib/node_modules/now/build/bin/now.js
lrwxr-xr-x   1 ignacio  staff        38 Feb 21 19:51 npm -> ../lib/node_modules/npm/bin/npm-cli.js
[~] | 02:08:04
@ignacio-air$ yarn global add grunt
yarn global v0.21.3
warning No license field
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Installed "[email protected]" with binaries:
      - grunt
warning No license field
โœจ  Done in 7.96s.
[~] | 02:08:18
@ignacio-air$ l $(yarn global bin)
total 69608
drwxr-xr-x   5 ignacio  staff       170 Mar  6 10:00 .
drwxr-xr-x  10 ignacio  staff       340 Feb 28 20:23 ..
-rwxr-xr-x   1 ignacio  staff  35629284 Feb 21 19:51 node
lrwxr-xr-x   1 ignacio  staff        40 Mar  6 10:00 now -> ../lib/node_modules/now/build/bin/now.js
lrwxr-xr-x   1 ignacio  staff        38 Feb 21 19:51 npm -> ../lib/node_modules/npm/bin/npm-cli.js

Other tools, that don't run with your .profile, .bashrc or whatever and expect binaries to be at recommended locations, they won't find those binaries you install with yarn globally and then they fail. Means, if some CLI tool uses a binary installed with yarn, can possibly fail. That's why I wish that binaries installed with yarn global add are symlinked to /usr/local/bin (at least on mac, I should mention this, linux might be a different situation).

On my ubuntu 16.04 machine , it worked when I added export PATH="$PATH:yarn global bin:$HOME/.config/yarn/global/node_modules/.bin" to my ~/.zshrc file.

@bestander, you said:

You just need to add ~/.config/yarn/global/node_modules/.bin to your PATH.

Sounds like it's the default/normal way to do it.

This was reported for Yarn v0.20.3 (February). Now, I use the latest v1.3.2 (as of December) and it's still the same. (yarn installed with brew)

I'm not saying it's taking too long. I'm curious, is this considered a bug at all?

@onury, I think it just slipped through. The core team is all busy working on fundamental stuff to make sure that Yarn works correctly and performs. Package management is a competitive business these days. :)

Brew installer has been maintained by the community in the past, so it is probably a matter of updating the cook book with that line.
Are you up to send a PR there?

@bestander I'd be glad to help but I don't have the time right now. Maybe (with some guidance) later I can chip in.

@bestander I'm inclined to say it's not a problem with the brew installer.

Problem persists in the node 9.4.0 docker container (yarn 1.3.2)

node@8d998466033a:~$ yarn global add @angular/cli
yarn global v1.3.2
[1/4] Resolving packages...


[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "@angular/[email protected]" with binaries:
      - ng
Done in 207.77s.
node@8d998466033a:~$ ng g component foo
bash: ng: command not found
node@8d998466033a:~$ ls ~/.config/yarn/global/node_modules/.bin/
ng
node@8d998466033a:~$ yarn --version
1.3.2
node@8d998466033a:~$ node --version
v9.4.0

Ok, that might be still a problem for some environments.
Anyone volunteers to help a bit more and get to the bottom of this why the Yarn's bin is not in PATH?
It is somewhat related to this PR https://github.com/yarnpkg/yarn/pull/5343 where we refactor some of the default paths.

Was this page helpful?
0 / 5 - 0 ratings