gem install permission problem

Ruby on-RailsRubyGem

Ruby on-Rails Problem Overview


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

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Try setting GEM_HOME and GEM_PATH to ~/.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 ~/.bashrc file.

For a more comprehensive solution to setting up a custom ruby environment, see this tutorial from Site5KB, which describes using a .gemrc file.

Solution 2 - Ruby on-Rails

For a systemwide Ruby install, become root. For example:

$ 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.

# 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

Solution 3 - Ruby on-Rails

I was getting this error on my shared server through 1and1 hosting. my solution was adding the --user-install option, which just installs it for your logged in user (which is all you need in a shared server environment) example; installing sass

gem install sass --user-install

Solution 4 - Ruby on-Rails

If you're using rbenv and this is happening, you need to add the following to your .bash_profile:

export RBENV_ROOT="$HOME/.rbenv"

if [ -d $RBENV_ROOT ]; then
  export PATH="$RBENV_ROOT/bin:$PATH"
  eval "$(rbenv init -)"
fi

Solution 5 - Ruby on-Rails

re-install ruby resolve my problem.

brew install ruby

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionqichunrenView Question on Stackoverflow
Solution 1 - Ruby on-Railsuser229044View Answer on Stackoverflow
Solution 2 - Ruby on-RailsyfeldblumView Answer on Stackoverflow
Solution 3 - Ruby on-RailsMaxView Answer on Stackoverflow
Solution 4 - Ruby on-RailsKevin QiView Answer on Stackoverflow
Solution 5 - Ruby on-RailsjackyshanView Answer on Stackoverflow