Ruby-on-rails 指定gem安装目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16098757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Specify gem installation directory
提问by Almaron
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.
我这里有些麻烦。我正在处理一个 Rails 2.3 项目(通过 ssh 在生产服务器上工作 - 不要问为什么)。这是Gemfile。当 delay_jobs 尝试启动时,输出显示我需要安装 bundler gem。问题是 gemdir 是 /var/lib/gems/1.8/ 并且我没有该目录的写权限。但是,在 ~/projects/shared/gems/ruby/1.8/gems 下有一个目录可以写。
How can I define the installation path for a gem?
如何定义 gem 的安装路径?
采纳答案by dpaluy
You can add the following to your config.rufile:
您可以将以下内容添加到config.ru文件中:
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:
还要配置您的服务器.bashrc:
export GEM_HOME="$HOME/projects/shared/gems/ruby/1.8/gems"
export GEM_PATH="$GEM_HOME:/var/lib/ruby/gems/1.8"
回答by Oleg Afanasyev
To install foogem to a specified folder, just use --install-diroption, i.e.
要将foogem安装到指定文件夹,只需使用--install-dir选项,即
$ gem install --install-dir /path/to/gems/folder foo
It helps when:
在以下情况下它会有所帮助:
- one cannot use
bundle install- e.g. if one wants to install bundlegem itself, or wants to install a gem (which is not listed in Gemfile) into the bundlefolder sudo gem installcommand fails due to lack of write-permissions for a default installation path
- 不能使用
bundle install- 例如,如果想要安装bundlegem 本身,或者想要将 gem(未在 Gemfile 中列出)安装到bundle文件夹中 sudo gem install由于缺少默认安装路径的写权限,命令失败
Hope that helps.
希望有帮助。
回答by IKA
The environment variable GEM_HOMEdefines the gem installation location. You need to set it to desired location. The command is OS specific.
环境变量GEM_HOME定义了 gem 安装位置。您需要将其设置到所需的位置。该命令是特定于操作系统的。
In Windows it is set
在 Windows 中它是 set
set GEM_HOME=[path]/projects/shared/gems/ruby/1.8/gems
Linux would be export
Linux 将是 export
export GEM_HOME=~/projects/shared/gems/ruby/1.8/gems
回答by Brad
bundler accepts a --path option.
bundler 接受一个 --path 选项。
bundle install --path vendor/bundle

