Bundler cannot install any gems without sudo

You may host gems in your user home folder, that does not need root permissions:

bundle install --path ~/.gem

To avoid passing this parameter manually add export GEM_HOME=$HOME/.gem to your .bash_profile — this solves sudo issue on Mac OS and other *nix systems. You then also might need to have access to gems that provide executables (such as bundler), so add this too:

PATH=$PATH:$HOME/.gem/bin

or in some cases:

PATH=$PATH:$HOME/.gem/ruby/<version>/bin

ref: https://stackoverflow.com/a/5862327/322020


UPD: But keep in mind that if you start using rbenv having this environment variable be the same might cause problems when using too different versions of Ruby, so you might want to temporary unset GEM_HOME or prepend custom one each time you launch rbenv-ed Ruby.

Leave a Comment