yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Possible to set the global install path

Open fortes opened this issue 10 years ago • 29 comments

This is a feature (or perhaps documentation request).

When I run the following:

yarn global add create-react-app

Yarn will try to symlink into /usr/bin which requires sudo. With NPM, I've set my global packages to install into a user directory that is then added to my $PATH.

Is it possible to set a global directory via config somehow?

I've tried the following to no avail:

yarn add create-react-app -g --global-folder ~/bin (installs into ~/node_modules) yarn global add create-react-app --global-folder ~/bin (still goes for /usr/bin)

This is all running on Debian 8.5

fortes avatar Oct 11 '16 16:10 fortes

It's not currently supported but we can definently add an option.

sebmck avatar Oct 11 '16 16:10 sebmck

This is a really important feature and a must have IMO.

So +1.

theduke avatar Oct 11 '16 16:10 theduke

If you install node to a user-owned location and set your own PATH, this already appears to work.

I always unpack node to a place like ~/Library/node-v6.7.0-darwin-x64, symlink that to ~/Library/node, and then add ~/Library/node/bin to PATH. Under those conditions, yarn correctly puts globals in the same place npm does, and sudo is not required.

ef4 avatar Oct 11 '16 16:10 ef4

This feature is very helpful for people who are unable to (or merely inclined against) running package installation operations, which sometimes download and execute staggering amounts of code of questionable provenance, as root.

kylecordes avatar Oct 11 '16 21:10 kylecordes

The npm option here is --prefix, so although it's very not recommended to use it, it'd be good to keep the same terminology.

ljharb avatar Oct 11 '16 23:10 ljharb

Rather than pass an option to npm, I have prefix=${HOME}/.local in my ~/.npmrc. It'd be great if yarn respected that (and other config settings), so that it could a true drop-in replacement for npm.

markrian avatar Oct 12 '16 09:10 markrian

Notice that you can already add ~/.yarn-cache/.global/node_modules/.bin/ (aka what is outputed by yarn global bin) to your PATH, the only problem is the linking to /usr/bin that should be easy to disable!

victornoel avatar Oct 12 '16 11:10 victornoel

Notice that you can already add (…) to your PATH

Instead of adding another directory to my PATH (which then means I’d have to do so in every other tool as well) I’d rather be able to set an option to link the binaries to wherever I want at install time.

vitorgalvao avatar Oct 13 '16 19:10 vitorgalvao

is this going to be fixed or is this a wont fix. its seems to be one of the most requested bugs.

related ones: #1389, #1388, #1321, #1226, #1194, #1151, #1060, #1029, #927 (comment), #630, #1370

sandys avatar Oct 28 '16 06:10 sandys

#1600 might also be related

dheerajbhaskar avatar Nov 01 '16 18:11 dheerajbhaskar

Created #1654 to fix this, pending approval.

sebmck avatar Nov 03 '16 14:11 sebmck

Linked PR makes it possible to do:

$ yarn global add react-native-cli --prefix /my-custom-prefix

sebmck avatar Nov 03 '16 14:11 sebmck

Linked PR makes it possible to do:

$ yarn global add react-native-cli --prefix /my-custom-prefix

What would be the correct way to make such a prefix permanent? Is there a line we can add to .bashrc (or whatever)?

vitorgalvao avatar Nov 03 '16 14:11 vitorgalvao

It should get the default npm path:

npm config get prefix

You can run this insted

yarn global add react-native-cli --prefix $(npm config get prefix)

tadeugr avatar Dec 17 '16 18:12 tadeugr

@tadeugr If your comment was in reply to my question, it doesn’t answer it. The question was about making a custom path the default without having to continuously use --prefix.

The answer is export PREFIX='/my-custom-prefix' in your shell’s startup files. Can’t help but think PREFIX is awfully generic and we should have something else.

vitorgalvao avatar Dec 17 '16 19:12 vitorgalvao

@vitorgalvao you can play around with it. For example, I put this in my .bashrc file:

export prefix=$(npm config get prefix)
export NODE_PATH=$(npm root -g)

tadeugr avatar Dec 17 '16 20:12 tadeugr

Any news on your question @vitorgalvao?

nachoaIvarez avatar Jan 21 '17 16:01 nachoaIvarez

@nachoaIvarez https://github.com/yarnpkg/yarn/issues/630#issuecomment-267783379.

vitorgalvao avatar Jan 21 '17 16:01 vitorgalvao

@vitorgalvao Oh, I thought that was a wish, not the answer. Thank you.

nachoaIvarez avatar Jan 21 '17 16:01 nachoaIvarez

The answer is export PREFIX='/my-custom-prefix' in your shell’s startup files.

having to define PREFIX as a global environment variable is absolutely not a solution, because that variable used by many programs to define other things, for example make.

phiresky avatar Jan 25 '17 22:01 phiresky