从系统中删除红宝石

时间:2011-10-24 10:45:16

标签: ruby rubygems gem

root@app1:~# gem -v
1.8.10

当我使用rvm时,我得到1.8.10。但是当我使用sudo时,我得到了:

root@app1:~# sudo gem -v
1.3.7

现在我在另一个用户上安装gem而不是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

哪里出错了?

当我不使用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

当我使用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 

1 个答案:

答案 0 :(得分:2)

这里要注意三件事:

  1. RVM通过维护几个环境变量来工作。 sudo在用户切换期间清除其中的大多数作为安全措施,以防止攻击者将危险变量(如LD_PRELOAD)注入提升的执行上下文。如果您想使用sudo并希望在新shell中保留RVM环境,请改用rvmsudo
  2. 您以root身份查看的gem环境是系统的默认设置。你得到这个,因为,如第一点所述,sudo在用户切换期间不保留RVM的环境变量。
  3. 您的gem安装尝试期间的错误很可能源于您没有正确的权限写入RVM目录。在全局安装期间,RVM会创建一个名为rvm的组,并确保其所有成员都可以写入需要安装rubies,创建gemsets和安装gem的RVm目录。确保您的用户在该组中。或者您可以使用rvmsudo ...