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

Always install gems to system gems #170

Closed
philc opened this Issue Mar 4, 2010 · 29 comments

Comments

Projects
None yet
8 participants
@philc

philc commented Mar 4, 2010

Currently, Bundler will install to ~/.bundle or the path defined by BUNDLE_HOME. This has a few disadvantages:

  1. The location is hidden and not displayed the first time you run bundle install, which can result in confusion. See issue #164.
  2. The location is not accessible via the standard gem tools, so "gem list installed" will not list the gems that bundler has reported as being installed after running "bundle install". This is especially confusing given that the path in #1 is not well known.
  3. Using the gems installed by bundler requires bundler.

To give some context behind this feature request, my company deploys only one app to a machine and so is fine with having that app's dependencies exist in the system rubygems location. Additionally, there are many auxiliary scripts which run besides the application (single-file scripts, cron jobs) which make use of some of the gems that the main application depends on. If the main app uses Bundler to install and enforce its gems, then the scripts must also do so, or they will not be able to require the same gems that the main application does. This seems overly burdensome.

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 4, 2010

Member

The location any gem is installed to is now exposed via bundle show GEM. Furthermore, you are perfectly welcome to set BUNDLE_HOME to the same path as your GEM_HOME. That will "fix" both point 2 and 3 that you mention. Unfortunately, that cannot possibly be the default, because it is not a workable solution on any machine where writing to GEM_HOME requires superuser rights.

Member

indirect commented Mar 4, 2010

The location any gem is installed to is now exposed via bundle show GEM. Furthermore, you are perfectly welcome to set BUNDLE_HOME to the same path as your GEM_HOME. That will "fix" both point 2 and 3 that you mention. Unfortunately, that cannot possibly be the default, because it is not a workable solution on any machine where writing to GEM_HOME requires superuser rights.

@philc

This comment has been minimized.

Show comment
Hide comment
@philc

philc Mar 4, 2010

I didn't recommend it be the default, and when writing to GEM_HOME requires super user privileges, why isn't running bundle install with sudo an option?

philc commented Mar 4, 2010

I didn't recommend it be the default, and when writing to GEM_HOME requires super user privileges, why isn't running bundle install with sudo an option?

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 4, 2010

Andre what about:

$ bundle install
> Sorry GEM_HOME requires superuser privileges do you want install gems in: ~/.bundle ? (y/n)
----------------------
$ sudo bundle install # install to system wide
----------------------
$ bundle install -y # install directly to ~/.bundle

DAddYE commented Mar 4, 2010

Andre what about:

$ bundle install
> Sorry GEM_HOME requires superuser privileges do you want install gems in: ~/.bundle ? (y/n)
----------------------
$ sudo bundle install # install to system wide
----------------------
$ bundle install -y # install directly to ~/.bundle
@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 5, 2010

Member

Thanks for the suggestions. We want bundler to just work in the standard case, and not ever require sudo.

However, if you (or anyone) wants to install bundled gems to the system gems location with superuser permissions, you can simply set BUNDLE_PATH to the system gems location, and then run sudo bundle install.

Member

indirect commented Mar 5, 2010

Thanks for the suggestions. We want bundler to just work in the standard case, and not ever require sudo.

However, if you (or anyone) wants to install bundled gems to the system gems location with superuser permissions, you can simply set BUNDLE_PATH to the system gems location, and then run sudo bundle install.

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 5, 2010

Andre,

for me can be done. But in my opinion bundler is a little complicated for newbies. That are some question that some people ask to me:

  1. I do bundle install but where I see installed gems?
  2. Why if I set Bundler.setup(:foo) I need before (also if I've already these gems) do bundle install --without ...
  3. I don't love have gems in two paths how I can fix bundler to use system path?
  4. Where is in osx GEM_HOME path?

I think not all of us are super expert and Im following some bundler issues and as you can see most are "misunderstanding" questions.

In my opinion bundler need to be more more more user friendly. Think for example when Rails 3 is out, how many newbie guys use it? Do you think that all of them can set a ENV path in their system?

I think that my last comment can help so much a lot of people preserving protected scenarios.

DAddYE commented Mar 5, 2010

Andre,

for me can be done. But in my opinion bundler is a little complicated for newbies. That are some question that some people ask to me:

  1. I do bundle install but where I see installed gems?
  2. Why if I set Bundler.setup(:foo) I need before (also if I've already these gems) do bundle install --without ...
  3. I don't love have gems in two paths how I can fix bundler to use system path?
  4. Where is in osx GEM_HOME path?

I think not all of us are super expert and Im following some bundler issues and as you can see most are "misunderstanding" questions.

In my opinion bundler need to be more more more user friendly. Think for example when Rails 3 is out, how many newbie guys use it? Do you think that all of them can set a ENV path in their system?

I think that my last comment can help so much a lot of people preserving protected scenarios.

@samhendley

This comment has been minimized.

Show comment
Hide comment
@samhendley

samhendley Mar 19, 2010

I would like to agree with the OP, it would be great if I can use bundler to install to the system when desired. If all it requires is setting GEM_PATH or BUNDLE_PATH to point to the system location then it would be great if we had a command line option that did that. I have been using Gemfiles mainly to document and verify which gems I am using but I hate having to have my CI server download the gems locally everytime. Something like: sudo bundle install --system-wide would be awesome!

samhendley commented Mar 19, 2010

I would like to agree with the OP, it would be great if I can use bundler to install to the system when desired. If all it requires is setting GEM_PATH or BUNDLE_PATH to point to the system location then it would be great if we had a command line option that did that. I have been using Gemfiles mainly to document and verify which gems I am using but I hate having to have my CI server download the gems locally everytime. Something like: sudo bundle install --system-wide would be awesome!

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 19, 2010

Member

@samhendley, sudo bundle anything is not possible unless your app runs as root. And you don't want to do that, because it's a massive security hole. Just make sure you have write permissions to $GEM_HOME, and then export BUNDLE_PATH=$GEM_HOME.

Member

indirect commented Mar 19, 2010

@samhendley, sudo bundle anything is not possible unless your app runs as root. And you don't want to do that, because it's a massive security hole. Just make sure you have write permissions to $GEM_HOME, and then export BUNDLE_PATH=$GEM_HOME.

@philc

This comment has been minimized.

Show comment
Hide comment
@philc

philc Mar 19, 2010

No one is arguing that you don't run the command with sudo. If bundler is run from the command line, you will be prompted to type the password. If it's run from a script or cron, it's up to the sys admn/developer to establish sudo rights before the script is run.

philc commented Mar 19, 2010

No one is arguing that you don't run the command with sudo. If bundler is run from the command line, you will be prompted to type the password. If it's run from a script or cron, it's up to the sys admn/developer to establish sudo rights before the script is run.

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 19, 2010

Member

@philc I'm sorry that it's inconvenient for you to set an environment variable, but Bundler is not going to automatically self-elevate to root if GEM_HOME is not writable.

Member

indirect commented Mar 19, 2010

@philc I'm sorry that it's inconvenient for you to set an environment variable, but Bundler is not going to automatically self-elevate to root if GEM_HOME is not writable.

@samhendley

This comment has been minimized.

Show comment
Hide comment
@samhendley

samhendley Mar 19, 2010

I think we may be talking at cross purposes here. I think the dominant use case you made and use bundler for is situations like heroku and many user level accounts all having their gem requirements. In that situation it makes perfect sense to not want to be able to put gems into the system root. In the case of heruko, i believe (never used it) the whole application deployment includes checking and installing the bundled gems all as one step as one user. Clearly you wouldn't want the user to have to run as root in this case.

What I, and I think philc, are using bundler for is a way to specify what gems we are using so that users and fellow developers can easily get the correct versions installed. I really only started using bundler because of that conviniance (and the ability to install from a git repo!). I have older ruby scripts that have no knowledge of bundler that I was trying not to edit, just adding gem documentation (in the form of the executable Gemfile) to make deployment easier. What I was really hoping for was a way to do what I had always done before bundler ie. "sudo gem install XXXX" for every gem and replace that with "sudo bundle install --system-wide".

It wasn't obvious to me that it was as simple as setting the BUNDLE_PATH variable before running it. What I don't have is GEM_HOME defined on most of my platforms. Bundler appears to know how to figure that out even when its not present in the environment variables, which is why I was hoping that functionality can be embedded in bundler. Basically I think there are people who want to use Bundler to install and amange gems system-wide but don't want to use the runtime support, adding this "syntactic sugar" would make that much easier.

samhendley commented Mar 19, 2010

I think we may be talking at cross purposes here. I think the dominant use case you made and use bundler for is situations like heroku and many user level accounts all having their gem requirements. In that situation it makes perfect sense to not want to be able to put gems into the system root. In the case of heruko, i believe (never used it) the whole application deployment includes checking and installing the bundled gems all as one step as one user. Clearly you wouldn't want the user to have to run as root in this case.

What I, and I think philc, are using bundler for is a way to specify what gems we are using so that users and fellow developers can easily get the correct versions installed. I really only started using bundler because of that conviniance (and the ability to install from a git repo!). I have older ruby scripts that have no knowledge of bundler that I was trying not to edit, just adding gem documentation (in the form of the executable Gemfile) to make deployment easier. What I was really hoping for was a way to do what I had always done before bundler ie. "sudo gem install XXXX" for every gem and replace that with "sudo bundle install --system-wide".

It wasn't obvious to me that it was as simple as setting the BUNDLE_PATH variable before running it. What I don't have is GEM_HOME defined on most of my platforms. Bundler appears to know how to figure that out even when its not present in the environment variables, which is why I was hoping that functionality can be embedded in bundler. Basically I think there are people who want to use Bundler to install and amange gems system-wide but don't want to use the runtime support, adding this "syntactic sugar" would make that much easier.

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 19, 2010

Member

If you haven't set GEM_HOME, Rubygems just uses $PREFIX/lib/ruby/gems/1.8.

If you want to use bundler to manage your gems system-wide, just set BUNDLE_PATH to the system-wide gems directory, and make sure you can write to it.

Member

indirect commented Mar 19, 2010

If you haven't set GEM_HOME, Rubygems just uses $PREFIX/lib/ruby/gems/1.8.

If you want to use bundler to manage your gems system-wide, just set BUNDLE_PATH to the system-wide gems directory, and make sure you can write to it.

@philc

This comment has been minimized.

Show comment
Hide comment
@philc

philc Mar 19, 2010

samhendley articulated well the use case I and many others will be using Bundler for, and the confusion that's present today when first trying out Bundler.

The folks on my dev team would expect this option to be available (and explicit) when cutting over to Bundler, and having to munge with environment variables instead will be a usability hit. You seem pretty set on not adding this feature, which is fair enough. The only thing I'd advise is to keep this bug open and triaged out of the way (under a label of suggestions or asks) and track how many folks you see ask for this over the next 6 months. This way you will have some solid data when reevaluating this decision in the future. I'm betting the lack of this option is going to cause more confusion than you expect, and it would be a shame for this bug to get lost in the abyss of closed bugs.

philc commented Mar 19, 2010

samhendley articulated well the use case I and many others will be using Bundler for, and the confusion that's present today when first trying out Bundler.

The folks on my dev team would expect this option to be available (and explicit) when cutting over to Bundler, and having to munge with environment variables instead will be a usability hit. You seem pretty set on not adding this feature, which is fair enough. The only thing I'd advise is to keep this bug open and triaged out of the way (under a label of suggestions or asks) and track how many folks you see ask for this over the next 6 months. This way you will have some solid data when reevaluating this decision in the future. I'm betting the lack of this option is going to cause more confusion than you expect, and it would be a shame for this bug to get lost in the abyss of closed bugs.

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 20, 2010

Member

I have reopened this bug and marked it for discussion, but again, there are already two ways to get exactly what you are asking for:

  1. export BUNDLE_PATH=$GEM_HOME
  2. Run sudo chmod +w $(whoami) $GEM_HOME

If you do either of those things before running bundle install you'll get exactly what you're asking for.

Member

indirect commented Mar 20, 2010

I have reopened this bug and marked it for discussion, but again, there are already two ways to get exactly what you are asking for:

  1. export BUNDLE_PATH=$GEM_HOME
  2. Run sudo chmod +w $(whoami) $GEM_HOME

If you do either of those things before running bundle install you'll get exactly what you're asking for.

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 23, 2010

Andre, nubble quesiton but this: Run sudo chmod +w $(whoami) $GEM_HOME didn't work for gems like rails that have a bin file... or I missing something?

DAddYE commented Mar 23, 2010

Andre, nubble quesiton but this: Run sudo chmod +w $(whoami) $GEM_HOME didn't work for gems like rails that have a bin file... or I missing something?

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 23, 2010

Member

I'm sorry, but I didn't understand your question at all. What are you trying to do?

Member

indirect commented Mar 23, 2010

I'm sorry, but I didn't understand your question at all. What are you trying to do?

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 24, 2010

I think that gems that have executables cannot be installed also after your two steps... because is necessary +w also in /bin or /usr/bin...

DAddYE commented Mar 24, 2010

I think that gems that have executables cannot be installed also after your two steps... because is necessary +w also in /bin or /usr/bin...

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Mar 24, 2010

Member

If (and only if) you are using OS X, RubyGems will try to install binaries into /usr/bin. You can fix that by adding a line like this to your ~/.gemrc file:

gem: -n/path/to/GEM_HOME/bin

Then even your binaries will be installed into $GEM_HOME, so you're set.

Member

indirect commented Mar 24, 2010

If (and only if) you are using OS X, RubyGems will try to install binaries into /usr/bin. You can fix that by adding a line like this to your ~/.gemrc file:

gem: -n/path/to/GEM_HOME/bin

Then even your binaries will be installed into $GEM_HOME, so you're set.

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 24, 2010

Yep! Super thanks Andre!

DAddYE commented Mar 24, 2010

Yep! Super thanks Andre!

@richievos

This comment has been minimized.

Show comment
Hide comment
@richievos

richievos Apr 20, 2010

+1 on the --system-wide flag. Yes it's redundant, but it's also simplifying a reasonable use-case (I've wanted this same behavior before). I totally agree it shouldn't auto-sudo itself, but I do think sudo bundler install --system-wide's a rather elegant feeling flag.

richievos commented Apr 20, 2010

+1 on the --system-wide flag. Yes it's redundant, but it's also simplifying a reasonable use-case (I've wanted this same behavior before). I totally agree it shouldn't auto-sudo itself, but I do think sudo bundler install --system-wide's a rather elegant feeling flag.

@samhendley

This comment has been minimized.

Show comment
Hide comment
@samhendley

samhendley Apr 21, 2010

I still would really like this feature but im not 100% sure that its as simple as just setting the bundle path to point to the gem home directory, i haven't tried to reproduce it recently but there seemed to be an issue where it would try to install gems from "system gems" into the bundle path (which was set to same location) and then it would get confused, running bundle check would say that all gems installed but then running the app would complain the gems weren't in bundle.

BTW can we change the title of this issue? Its really turned into more a --system-wide discussion rather than the auto promotion to root thing.

samhendley commented Apr 21, 2010

I still would really like this feature but im not 100% sure that its as simple as just setting the bundle path to point to the gem home directory, i haven't tried to reproduce it recently but there seemed to be an issue where it would try to install gems from "system gems" into the bundle path (which was set to same location) and then it would get confused, running bundle check would say that all gems installed but then running the app would complain the gems weren't in bundle.

BTW can we change the title of this issue? Its really turned into more a --system-wide discussion rather than the auto promotion to root thing.

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Apr 21, 2010

Member

For the record, our current stance on system gems is that Bundler 0.9 will continue to use ~/.bundle, but 0.10 will try as hard as it possibly can to simply use system gems.

Member

indirect commented Apr 21, 2010

For the record, our current stance on system gems is that Bundler 0.9 will continue to use ~/.bundle, but 0.10 will try as hard as it possibly can to simply use system gems.

@samhendley

This comment has been minimized.

Show comment
Hide comment
@samhendley

samhendley Apr 21, 2010

thats great to hear. thanks for the update

samhendley commented Apr 21, 2010

thats great to hear. thanks for the update

@philc

This comment has been minimized.

Show comment
Hide comment
@philc

philc May 2, 2010

To be clear, does "use" mean bundler will attempt to install to the system gems as well as resolve its dependencies from the system gems?

philc commented May 2, 2010

To be clear, does "use" mean bundler will attempt to install to the system gems as well as resolve its dependencies from the system gems?

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect May 2, 2010

Member

Bundler 0.9 will not attempt to install to system gems unless BUNDLE_PATH is set to GEM_HOME and bundler has write access.

Bundler 0.10 will attempt to install to GEM_HOME first, and fall back on various backup options (including sudo and ~/.bundle, exact details TBD.)

Member

indirect commented May 2, 2010

Bundler 0.9 will not attempt to install to system gems unless BUNDLE_PATH is set to GEM_HOME and bundler has write access.

Bundler 0.10 will attempt to install to GEM_HOME first, and fall back on various backup options (including sudo and ~/.bundle, exact details TBD.)

@philc

This comment has been minimized.

Show comment
Hide comment
@philc

philc May 2, 2010

Awesome, you rock.

philc commented May 2, 2010

Awesome, you rock.

@trans

This comment has been minimized.

Show comment
Hide comment
@trans

trans May 22, 2010

Contributor

Please, instead of ~/.bundle as the backup, use the XDG directory standard.

Contributor

trans commented May 22, 2010

Please, instead of ~/.bundle as the backup, use the XDG directory standard.

@indirect

This comment has been minimized.

Show comment
Hide comment
@indirect

indirect Jun 14, 2010

Member

Closing this as complete in the Bundler 1.0.beta1 release

Member

indirect commented Jun 14, 2010

Closing this as complete in the Bundler 1.0.beta1 release

@zhenninglim

This comment has been minimized.

Show comment
Hide comment
@zhenninglim

zhenninglim Nov 21, 2014

So, how to fix the issue? I am trying to install gems from git using bundler. Bundler seems to still install it inside ~./bundler. I tried to install ruby somewhere other than /usr, then bundle cant find the ruby... And after i set the bundler path to my ruby gems path, it creates extra directories ruby/gems/2.1.0/bundler/gems/package

zhenninglim commented Nov 21, 2014

So, how to fix the issue? I am trying to install gems from git using bundler. Bundler seems to still install it inside ~./bundler. I tried to install ruby somewhere other than /usr, then bundle cant find the ruby... And after i set the bundler path to my ruby gems path, it creates extra directories ruby/gems/2.1.0/bundler/gems/package

@TimMoore

This comment has been minimized.

Show comment
Hide comment
@TimMoore

TimMoore Nov 21, 2014

Member

@zhenninglim git gems are a Bundler-specific feature that works outside the normal gem installation process.

Member

TimMoore commented Nov 21, 2014

@zhenninglim git gems are a Bundler-specific feature that works outside the normal gem installation process.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment