Skip to content
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

Possible to set the global install path #630

Closed
fortes opened this issue Oct 11, 2016 · 29 comments
Closed

Possible to set the global install path #630

fortes opened this issue Oct 11, 2016 · 29 comments

Comments

@fortes
Copy link

fortes commented Oct 11, 2016

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

@sebmck
Copy link
Contributor

sebmck commented Oct 11, 2016

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

@theduke
Copy link

theduke commented Oct 11, 2016

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

So +1.

@ef4
Copy link

ef4 commented Oct 11, 2016

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.

@kylecordes
Copy link

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.

@ljharb
Copy link

ljharb commented Oct 11, 2016

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.

@markrian
Copy link

markrian commented Oct 12, 2016

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.

@victornoel
Copy link
Contributor

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!

@vitorgalvao
Copy link

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.

@sandys
Copy link

sandys commented Oct 28, 2016

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

@dheerajbhaskar
Copy link

#1600 might also be related

@sebmck
Copy link
Contributor

sebmck commented Nov 3, 2016

Created #1654 to fix this, pending approval.

@sebmck sebmck closed this as completed Nov 3, 2016
@sebmck sebmck removed the cat-feature label Nov 3, 2016
@sebmck
Copy link
Contributor

sebmck commented Nov 3, 2016

Linked PR makes it possible to do:

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

@vitorgalvao
Copy link

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)?

Jessidhia pushed a commit to Jessidhia/yarn that referenced this issue Nov 4, 2016
* master: (66 commits)
  Add --no-bin-links flag - fixes yarnpkg#929 (yarnpkg#1651)
  Add option to change the prefix of the global bin folder - fixes yarnpkg#630 (yarnpkg#1654)
  patterns -> filteredPatterns
  Add helpful nudge to yarnpkg/rfcs on issue template (yarnpkg#1650)
  Change reporter.log to console.log in generate-lock-entry command - fixes yarnpkg#644 (yarnpkg#1652)
  Fixed add command flag (yarnpkg#1653)
  Nested executables fix (yarnpkg#1210)
  Added short-flags for yarn add (yarnpkg#1618)
  Add name lookups to ls command - fixes yarnpkg#1599 (yarnpkg#1643)
  Disable flaky secureUrl test (yarnpkg#1644)
  Add unit tests for `yarn why`. (yarnpkg#1544)
  Refine flow type for config.generateHardModulePath (yarnpkg#1642)
  Use ~/Library/Caches as default cache location on OSX - fixes yarnpkg#1637 (yarnpkg#1638)
  Update aliases.js (yarnpkg#1635)
  Update aliases.js (yarnpkg#1634)
  Add webhook to archive AppVeyor build artifacts (yarnpkg#1631)
  Attempt to fix failing Circle CI builds (yarnpkg#1629)
  Adding 'yarn global upgrade'(Issue yarnpkg#776) (yarnpkg#1616)
  Show error message in stdout. (yarnpkg#1502)
  Nicer permission errors when trying to write global binaries - fixes yarnpkg#1578 (yarnpkg#1592)
  ...
@tadeugr
Copy link

tadeugr commented Dec 17, 2016

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)

@vitorgalvao
Copy link

@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.

@tadeugr
Copy link

tadeugr commented Dec 17, 2016

@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)

@nachoaIvarez
Copy link

Any news on your question @vitorgalvao?

@vitorgalvao
Copy link

@nachoaIvarez #630 (comment).

@nachoaIvarez
Copy link

nachoaIvarez commented Jan 21, 2017

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

@phiresky
Copy link

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.

@vitorgalvao
Copy link

having to define PREFIX as a global environment variable is absolutely not a solution

It absolutely is a solution. It deliberately works! Is it a good solution? No. But I mentioned that in the next sentence:

Can’t help but think PREFIX is awfully generic and we should have something else.

I don’t think this is the place to have that discussion, though. For all intents and purposes this issue is solved and closed. Having a better global variable should be its own specific issue.

@TimvdLippe
Copy link
Contributor

It seems that yarn config set prefix /usr/local/ works for me. Now when I do yarn global add X it creates the package in /usr/local/bin/X

@vitorgalvao
Copy link

Thank you @TimvdLippe. Definitely the right approach.

@bastilimbach
Copy link

@TimvdLippe thanks, this worked. But if you have some pre-installed packages from npm in the folder, yarn global ls doesn't list them. Anybody having the same issue?

@nachoaIvarez
Copy link

@bastilimbach That's expected behaviour. Yarn is looking somewhere else for global packages once you changed the place where global packages get installed. Thanks @TimvdLippe, that was definitely the solution we were looking for!

@bastilimbach
Copy link

@nachoaIvarez I fixed it by removing all packages and adding them back with yarn global add.

@Grawl
Copy link

Grawl commented Mar 1, 2017

@TimvdLippe

It seems that yarn config set prefix /usr/local/ works for me. Now when I do yarn global add X it creates the package in /usr/local/bin/X

not works with 0.21.3 on macOS

@delebash
Copy link

delebash commented Mar 3, 2017

@TimvdLippe
windows 7 x64

After setting the prefix it does work but the actual node_modules are still installed in AppData\Local\Yarn\config\global\node_modules. The prefix folder just contains the .cmd files. Is there anyway to change the actual install directory?

@terdia
Copy link

terdia commented Jun 23, 2017

This is the only reason why I have not switch to yarn, I need to install my front end packages in a specific folder.

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

No branches or pull requests