Specify gem installation directory

Go To StackoverFlow.com

22

I have some trouble here. I am working with a Rails 2.3 project (working on the production server through ssh - don't ask why). Here is the Gemfile. When delayed_jobs is trying to start, the output says I need to install the bundler gem. The problem is that the gemdir is /var/lib/gems/1.8/ and I don't have the write priviliges for that directory. However there is a directory under ~/projects/shared/gems/ruby/1.8/gems where I can write.

How can I define the installation path for a gem?

2013-04-19 06:43
by Almaron
not sure what you want, but if i understood question correctly, you can do bundle install --path yourpathher - sanny Sin 2013-04-19 08:14
The problem is to install the bundler itself. It's required for the app to work, but is not installed somehow - Almaron 2013-04-19 08:39
oh i see, ill let you know if i find some wa - sanny Sin 2013-04-19 09:04


12

You can add the following to your config.ru file:

ENV['GEM_HOME']="#{ENV['HOME']}/projects/shared/gems/ruby/1.8/gems"
ENV['GEM_PATH']="#{ENV['GEM_HOME']}:/var/lib/ruby/gems/1.8"
require 'rubygems'
Gem.clear_paths

This will tell your rack app where to look for gems.

Also configure your server .bashrc:

export GEM_HOME="$HOME/projects/shared/gems/ruby/1.8/gems"
export GEM_PATH="$GEM_HOME:/var/lib/ruby/gems/1.8"
2013-04-19 07:27
by dpaluy
Wtf is a config.ru file?. - ulidtko 2016-06-01 09:57
config.ru is a rack configuration file in your ap - dpaluy 2016-06-01 13:27
I don't have one. I don't have an app either. I'm trying to install someone else's tool in Ruby, and it requires certain gems. I'm uncomfortable with having to sudo gem install, and that's why I'm here looking for a way to fine-tune the gem path. Your answer doesn't give me what I'm looking for - ulidtko 2016-06-02 12:18


26

To install foo gem to a specified folder, just use --install-dir option, i.e.

$ gem install --install-dir /path/to/gems/folder foo

It helps when:

  • one cannot use bundle install - e.g. if one wants to install bundle gem itself, or wants to install a gem (which is not listed in Gemfile) into the bundle folder
  • sudo gem install command fails due to lack of write-permissions for a default installation path

Hope that helps.

2016-11-23 10:55
by Oleg Afanasyev


13

The environment variable GEM_HOME defines the gem installation location. You need to set it to desired location. The command is OS specific.

In Windows it is set

set GEM_HOME=[path]/projects/shared/gems/ruby/1.8/gems

Linux would be export

export GEM_HOME=~/projects/shared/gems/ruby/1.8/gems
2013-04-19 06:59
by IKA
Did that and got gem install to succeed. But the gem list command still does not show it installed, and when I try to use the bundle command it sais I need to install the gem. rvm gempath output features the shared gems path correctly - Almaron 2013-04-19 07:49
@Almaron try running 'gem install bundler' to install bundler gem in that location and enable usage of 'bundle' command - IKA 2013-04-19 08:08
I ran 'gem install bundler' and it said that gem was intalled successfully. But when I try running 'gem list' it does not show the gem installed. Also the bundle command is not working - Almaron 2013-04-19 08:40


0

bundler accepts a --path option.

bundle install --path vendor/bundle
2018-10-19 14:18
by Brad
Ads