Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify gem installation directory

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?

like image 397
Almaron Avatar asked Apr 19 '13 06:04

Almaron


People also ask

Where gem files are installed?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9.

How do I install a specific gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

What is gem install command?

The install command installs local or remote gem into a gem repository. For gems with executables ruby installs a wrapper file into the executable directory by default.


2 Answers

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.

like image 145
Oleg Afanasyev Avatar answered Oct 17 '22 00:10

Oleg Afanasyev


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" 
like image 38
dpaluy Avatar answered Oct 16 '22 23:10

dpaluy