user2285257
user2285257

Reputation:

Force bundler to install gems in user’s home directory

Last time I’m trying to learn how to do web development with Ruby on Rails and I use my Arch GNU/Linux machine for it. The policy of Arch requires gems to be installed in the user directory instead of usual system‐wide location. However, it contradicts the default behavior of the bundler (which tries to install gems system‐wide). So whenever I run rails new foo the bundler asks me to enter my root password.

I want to force bundler to install gems required by Rails in my home directory. I tried running bundle install --path .bundle but it downloads and installs all of the Rails gems one more time which is obviously what I don’t want to do.

Do you have any idea how to do it?

Update: Finally I’ve got a desired effect by running bundle install --path ~/.gem.

Upvotes: 32

Views: 13858

Answers (3)

Zaz
Zaz

Reputation: 48709

The even newer way to do this is:

bundle config set --local path '/home/username/.local/share/gem'
bundle install

This matches where gem install --user-install puts gems on most modern operating systems and follows the trend of decluttering the home directory.

Upvotes: 13

smoyth
smoyth

Reputation: 709

The new way to do this is to run

bundle config set --local path '/home/username/.gem'
bundle install

The --path argument is deprecated.

Upvotes: 6

Holger Frohloff
Holger Frohloff

Reputation: 1705

You can set an environment variables $BUNDLE_PATH or $GEM_HOME. Bundler will use those and install your gems there. If you specify --path my_path, Bundler will remember this value for future installations.

[…] but it downloads and installs all of the Rails gems one more time which is obviously what I don’t want to do.

If you want to use cached versions of your gems use --local.

Upvotes: 19

Related Questions