Skip to content

Change global prefix directory to /usr/local on OS X #3458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2017
Merged

Change global prefix directory to /usr/local on OS X #3458

merged 1 commit into from
Jun 23, 2017

Conversation

KishanBagaria
Copy link
Contributor

@KishanBagaria KishanBagaria commented May 19, 2017

When node is installed from Homebrew, node exists at /usr/local/Cellar/node/7.10.0/bin/node

So yarn's global bin directory (yarn global bin) becomes: /usr/local/Cellar/node/7.10.0/bin

$ node -e 'console.log(process.execPath)'
/usr/local/Cellar/node/7.10.0/bin/node
$ yarn global bin
/usr/local/Cellar/node/7.10.0/bin

This creates two problems:

  1. /usr/local/Cellar/node/(version)/bin is not present in PATH by default. Users have to modify their profile to extend PATH with yarn global bin.

  2. When node is upgraded, all linked global binaries become inaccessible since yarn global bin automatically gets changed to /usr/local/Cellar/node/(latest-version) from /usr/local/Cellar/node/(old-version). The global bin directory should remain constant on upgrades.

The fix is to simply use /usr/local/bin as the default global bin directory in OS X installations. NPM (npm --global prefix) also uses that directory (at least when installed from Homebrew).

This should also fix #1194.

Alternatives

  1. Instead of all OS X installations, this change can be applied only to installations where node is installed from Homebrew, by checking if process.execPath begins with /usr/local/Cellar. Although, this issue would still be present with nvm or some other node-installer.

  2. Instead of modifying yarn, a patch could be made in the Yarn formula to automatically run yarn config set prefix /usr/local. (EDIT: It's not possible atm: Yarn global packages with brew's node.js no longer work on node update. Homebrew/homebrew-core#7283 (comment)) Other node-installers like nvm will also require similar changes.

  3. In the getGlobalPrefix function, instead of

let prefix = path.dirname(path.dirname(process.execPath)); //=> /usr/local/Cellar/node/7.10.0

this could be used:

const whichNode = execa.sync('which', ['node']).stdout; //=> /usr/local/bin/node
let prefix = path.dirname(path.dirname(whichNode)); //=> /usr/local

@rally25rs
Copy link
Contributor

rally25rs commented May 19, 2017

I believe this PR would also fix: #2064
There is a lot of discussion in that thread related to this kind of change.

@bestander
Copy link
Member

Looping in @Daniel15 as I completely lost faith in trying to understand all those prefixes needed for every OS

@Daniel15
Copy link
Member

Daniel15 commented May 24, 2017

I'm not very familiar with Mac OS, but the issue on Linux would be that regular users normally don't have write access to /usr/local. My preferred fix here would be to use /usr/local if it's writable by the current user, otherwise use ~/.yarn/bin or something similar.

It might be easier to just always use a user directory like ~/.yarn/bin. On Windows we always use a user directory: %LOCALAPPDATA%\Yarn\bin (eg. C:\Users\Daniel\AppData\Local\Yarn\bin)

@bestander
Copy link
Member

To me it seems like a safe enough change for Mac OS, let's merge it.
Speak up if you want to revert it.

@KishanBagaria, you have expressed a few good ideas about paths in Linux.
Do you want to give it a try and help Yarn to provide a great experience with all those PATH problems?

@bestander bestander merged commit edfc370 into yarnpkg:master Jun 23, 2017
@paulirish
Copy link
Member

On Google corporate OS X machines /usr/local is owned by root, rather than the user. As a result, most Googlers with homebrew install to another location rather than only using homebrew via sudo (which is terrrible).

image

FWIW I've been manually adding my homebrew'd node path to PATH in order to make sure my yarn global installs work. And I rev this each time I upgrade node. It's kinda gross. :/

For me, it'd be perfect to install the global links into ~.yarn/bin (as I've expected them to be there multiple times). @Daniel15's proposal of falling back to there if /usr/local isn't writable is fine with me.

@bestander
Copy link
Member

Thanks for feedback @paulirish.
I'll revert this now.

@KishanBagaria would you give it another try with @Daniel15's feedback?

bestander added a commit that referenced this pull request Jun 24, 2017
bestander added a commit that referenced this pull request Jun 24, 2017
@KishanBagaria KishanBagaria deleted the osx-default-prefix branch June 26, 2017 07:23
@KishanBagaria
Copy link
Contributor Author

@paulirish That must needlessly require sudo for a lot of install scripts. Maybe you should drop the suggestion of making /usr/local user-accessible in their issue tracker.

Until the next Yarn release, you can simply run yarn config set prefix ~/.yarn and get rid of the hacks in your dotfile.

chrmoritz added a commit to chrmoritz/yarn that referenced this pull request Jul 27, 2017
This sets the global prefix in a homebrew installation to a configurable
package.json variable, which can be replaced by homebrew during formula
installation with the actual value of HOMEBREW_PREFIX (similar to how
installationMethod is already replaced there).
This commit is a improved version of yarnpkg#3458 with added support for custom
homebrew prefixes, which should address the issue from:
yarnpkg#3458 (comment)

Refs: yarnpkg#1194
Refs: Homebrew/homebrew-core#16083
chrmoritz added a commit to chrmoritz/yarn that referenced this pull request Jul 28, 2017
This sets the global prefix in a homebrew installation to a configurable
package.json variable, which can be replaced by homebrew during formula
installation with the actual value of HOMEBREW_PREFIX (similar to how
installationMethod is already replaced there).
This commit is an improved version of yarnpkg#3458 with added support for
custom homebrew prefixes, which should address the issue from:
yarnpkg#3458 (comment)

Refs: yarnpkg#1194
Refs: Homebrew/homebrew-core#16083
chrmoritz added a commit to chrmoritz/yarn that referenced this pull request Jul 28, 2017
This sets the global prefix in a homebrew installation to a configurable
package.json variable, which can be replaced by homebrew during formula
installation with the actual value of HOMEBREW_PREFIX (similar to how
installationMethod is already replaced there).
This commit is an improved version of yarnpkg#3458 with added support for
custom homebrew prefixes, which should address the issue from:
yarnpkg#3458 (comment)

Refs: yarnpkg#1194
Refs: Homebrew/homebrew-core#16083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Location of global bin doesn't match the doc
5 participants