Databaas
Databaas

Reputation: 51

remove ruby gems from system

root@app1:~# gem -v
1.8.10

I get 1.8.10 when I use rvm. But when I use sudo I get:

root@app1:~# sudo gem -v
1.3.7

Now when I install a gem on another user than root

test@app1:~$ gem install RedCloth
Fetching: RedCloth-4.2.8.gem (100%)
ERROR:  While executing gem ... (Errno::EACCES)
Permission denied - /usr/local/rvm/gems/ree-1.8.7-2011.03/cache/RedCloth-4.2.8.gem

Where does this go wrong?

Here is my gem env when i use no sudo

root@app1:~# gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/rvm/gems/ree-1.8.7-2011.03
- RUBY EXECUTABLE: /usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ree-1.8.7-2011.03/bin
- RUBYGEMS PLATFORMS:
- ruby
 - x86_64-linux
- GEM PATHS:
 - /usr/local/rvm/gems/ree-1.8.7-2011.03
 - /usr/local/rvm/gems/ree-1.8.7-2011.03@global
- GEM CONFIGURATION:
 - :update_sources => true
 - :verbose => true
 - :benchmark => false
 - :backtrace => false
 - :bulk_threshold => 1000
 - "gem" => "--no-rdoc --no-ri"
 - "install" => "--no-ri --no-rdoc --env-shebang"
 - :sources => ["http://gemcutter.org", "http://gems.rubyforge.org/",   "http://gems.github.com"]
 - "update" => "--no-ri --no-rdoc --env-shebang"
 - REMOTE SOURCES:
   - http://gemcutter.org
   - http://gems.rubyforge.org/
   - http://gems.github.com

Here is my gem env when i use sudo

root@app1:~# sudo gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
  - INSTALLATION DIRECTORY: /var/lib/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
    - /var/lib/gems/1.8
    - /root/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-rdoc --no-ri"
     - :sources => ["http://gemcutter.org", "http://gems.rubyforge.org/", "http://gems.github.com"]
     - "install" => "--no-ri --no-rdoc --env-shebang"
     - "update" => "--no-ri --no-rdoc --env-shebang"
  - REMOTE SOURCES:
     - http://gemcutter.org
     - http://gems.rubyforge.org/
     - http://gems.github.com 

Upvotes: 0

Views: 1125

Answers (1)

Holger Just
Holger Just

Reputation: 55718

Three things to note here:

  1. RVM works by maintaining a couple of environment variables. sudo clears most of them during user switch as a security measure to prevent attackers to inject dangerous variables like LD_PRELOAD into an elevated execution context. If you want to use sudo and want to retain your RVM environment inside the new shell, use rvmsudo instead.
  2. The gem environment you see as root is the system's default. You get this, because, as explained in point one, sudo doesn't retain RVM's environment variables during user switching.
  3. The error during your gem installation attempt most probably stems from you don't having the correct rights to write into the RVM directory. During a global installation, RVM creates a group called rvm and makes sure that all its members can write to the RVm directory which is requires to install rubies, create gemsets and install gems. Make sure your user is in that group. Or you could just use rvmsudo...

Upvotes: 2

Related Questions