Yarn: Consider making `--prefix /usr/local` a default so links don't get lost after upgrade

Created on 6 Feb 2017  路  6Comments  路  Source: yarnpkg/yarn

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

feature

What is the current behavior?

yarn global add will symlink binary to current installed node path, which will get lost after next upgrade. (if brew cleanup were ran too)

What is the expected behavior?

Ideally globally installed binary should be symlinked to /usr/local (on os x), currently one has to add --prefix /usr/local to make that happen, but most people will never notice that argument and it will surely cause a bunch of problems later on.

I'm proposing to either make --prefix /usr/local a default behavior, or a config option in .yarnrc where user could set the path once and for all.

Please mention your node.js, yarn and operating system version.
node: v7.5.0
yarn: 0.20.0
os: macOS 10.12.3

All 6 comments

I think stuff is already stored in /usr/local/share when running as root on Linux: https://github.com/yarnpkg/yarn/blob/df8ff3613b21f9e83847ee00b121f154954330a3/src/constants.js#L6-L8. I'm not sure if that includes executables though.

Normally regular users can't write to /usr/local, so I don't think it should be defaulted.

Out of curiosity, is it recommended to always run yarn as root on os x?

At least for now, on os x, writing to /usr/local is the only way to guarantee executables won't get wiped with every node upgrade, please let me know if otherwise, thanks.

Besides brew cleanup, Just running a yarn global add command will cause yarn itself to delete binaries in /usr/local/bin, even binaries for yarn itself! See #2627, in which yarn upgrades or downgrades itself each time I run yarn global add by deleting or re-adding a symlink to yarn in /usr/local/bin.

I disagree with the proposal to make -prefix default to /usr/local, because as @Daniel15 points out, normal users can run yarn global add, but they can't write to `/usr/local/.

I agree with the proposal to add a config option in .yarnrc where user could set the path once and for all..

I'm currently just tried a yarn global add as a normal user and for reasons that aren't clear, it tried to install to /usr/local/bin which I don't have access to write to, so that failed.

Neither https://yarnpkg.com/en/docs/cli/add nor https://yarnpkg.com/en/docs/cli/global currently document the --prefix option. Notably, it would be helpful to know a recommended default value for the case when a normal user runs yarn global add.

FYI, --prefix /usr/local is indeed documented here, at least in the code snippet, that's where I picked it up.

The original issue was reported on Mac, not Linux.

On Mac yarn installs to /usr/local/Cellar/node/{version} which has the same access rights as /usr/local/bin.

So switching from latter to former would not make any harm.

BTW, npm installs into /usr/local/bin.

Was this page helpful?
0 / 5 - 0 ratings