Why do gem and sudo gem have different installation directories?

Remember, I used gem install rails to install Rails, but today, when I want to install another stone, typing

 gem install ruby-recaptcha 

he fails saying:

You do not have permission to write to ...

Then I found that my gem environment and sudo gem environment have different results:

For gem environment :

 RubyGems Environment: - RUBYGEMS VERSION: 1.8.15 - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.0.1] - INSTALLATION DIRECTORY: /Users/hx/.rvm/gems/ruby-1.9.2-p290 - RUBY EXECUTABLE: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/bin/ruby - EXECUTABLE DIRECTORY: /Users/hx/.rvm/gems/ruby-1.9.2-p290/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-11 - GEM PATHS: - /Users/hx/.rvm/gems/ruby-1.9.2-p290 - /Users/hx/.rvm/gems/ ruby-1.9.2-p290@global - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - :gempath => ["/Users/hx/.rvm/gems/ruby-1.9.2-p290"] - :sources => ["http://rubygems.org/"] - REMOTE SOURCES: - http://rubygems.org/ 

For sudo gem environment :

  - RUBYGEMS VERSION: 1.8.15 - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.0.1] - INSTALLATION DIRECTORY: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/bin/ruby - EXECUTABLE DIRECTORY: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-11 - GEM PATHS: - /Users/hx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1 - /Users/hx/.gem/ruby/1.9.1 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - :gempath => ["/Users/hx/.rvm/gems/ruby-1.9.2-p290"] - :sources => ["http://rubygems.org/"] - REMOTE SOURCES: - http://rubygems.org/ 

It is noted that the installation directory is different. So when I use gem , I don’t have permissions (I don’t know why I suddenly lost permission). But when I use sudo gem , the gem does not set in the right place. How can i fix this?

+4
source share
1 answer

RVM uses environment variables to configure rubygems - gem commands, basically if you have a custom installation ( ~/.rvm ), you don’t need to use any sudo command to call any commands, especially gem , that if rail would work as the root user in your home directory, which makes it impossible to manage your files ... if you have good reason to use sudo - use rvmsudo instead - but you really shouldn't have what it takes, especially to install gems.

If you want some commands (e.g. gist ) available on your system, you can use rvm wrapper and its associated binary in /usr/bin

to fix permissions in your home:

 sudo chown $USER: ~/.rvm sudo chmod u+rw ~/.rvm 
+4
source

Source: https://habr.com/ru/post/1393778/


All Articles