Ruby-on-rails gem安装权限问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2619695/
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
gem install permission problem
提问by qichunren
qichunren@zhaobak:~> gem install hpricot
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8 directory.
Current login user is qichunren, and qichunre user have write permission with .gem dir.I would like to know why gem not install files into my home .gem dir first? Why my gem common first want to install files into /opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8
当前登录用户是qichunren,qichunre 用户有.gem 目录的写权限。我想知道为什么gem 不先将文件安装到我家的.gem 目录中?为什么我的gem common首先要安装文件到/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8
采纳答案by yfeldblum
For a systemwide Ruby install, become root. For example:
对于系统范围的 Ruby 安装,请成为 root。例如:
$ sudo gem install hpricot
However, the modern approach in many circumstances, including in development, is to use a tool that lets you easily install and use Ruby as a normal user. This lets you avoid having to become root. There are a few such tools, and the one I use is RVM.
但是,在许多情况下(包括在开发中)的现代方法是使用一种工具,让您能够以普通用户的身份轻松安装和使用 Ruby。这让您不必成为 root。有一些这样的工具,我使用的一个是RVM。
# install rvm into your ~
$ \curl -sSL https://get.rvm.io | bash -s stable
# install latest version of ruby into your ~
$ rvm install ruby
# installs a gem into your ~
$ gem install $SOME_GEM_NAME
回答by meagar
Try setting GEM_HOMEand GEM_PATHto ~/.gem,
尝试设置GEM_HOME和GEM_PATH到~/.gem,
For the current terminal session, just type:
对于当前的终端会话,只需键入:
export GEM_HOME=~/.gem
export GEM_PATH=~/.gem
If you want these to be set whenever you open a terminal, add the above commands to your ~/.bashrcfile.
如果您希望在打开终端时设置这些,请将上述命令添加到您的~/.bashrc文件中。
For a more comprehensive solution to setting up a custom ruby environment, see this tutorial from Site5KB, which describes using a .gemrcfile.
有关设置自定义 ruby 环境的更全面的解决方案,请参阅Site5KB 中的本教程,其中描述了使用.gemrc文件。
回答by Max
I was getting this error on my shared server through 1and1 hosting.
my solution was adding the --user-installoption, which just installs it for your logged in user (which is all you need in a shared server environment)
example; installing sass
我通过 1and1 托管在我的共享服务器上收到此错误。我的解决方案是添加--user-install选项,它只是为您的登录用户安装它(这是您在共享服务器环境中所需要的)示例;安装sass
gem install sass --user-install
回答by Kevin Qi
If you're using rbenv and this is happening, you need to add the following to your .bash_profile:
如果您正在使用 rbenv 并且发生这种情况,您需要将以下内容添加到您的 .bash_profile 中:
export RBENV_ROOT="$HOME/.rbenv"
if [ -d $RBENV_ROOT ]; then
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
fi
回答by Hymanyshan
re-install ruby resolve my problem.
重新安装 ruby 解决了我的问题。
brew install ruby

