Stop installing rubygems to your home directory when you don’t “sudo”
Problem
You don’t want to install rubygems under your home direcotry(~/.gem/ruby/1.x/) when you just forgot to “sudo” and don’t have right permissions to write to system directories.
Solution
First, You need to install rubygems newer than 1.3.2. To check the version, type as
gem -v
1.3.1To update your gems itself, type as
sudo gem update --system
Next, you need to edit your ~/.gemrc file. Add
gem: --no-user-install
at the bottom of the file.
Now, if you forgot to “sudo” when installing new rubygems, gem will simply fail with permission erros, like
tomoya@hongkong% gem install sequel ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /opt/local/lib/ruby/gems/1.8 directory.