Force bundler to install gems in user’s home direc

2019-03-24 11:13发布

问题:

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.

回答1:

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.