how to install gems without sudo

后端 未结 7 501
萌比男神i
萌比男神i 2020-12-05 00:29

On all my gem installs I have to do sudo ? So

sudo gem install rails

will work, while only

gem install

7条回答
  •  青春惊慌失措
    2020-12-05 00:36

    When you install them without sudo, Ruby doesn't know where they get installed to. I can't remember where it installs them by default, probably somewhere like ~/.gems or something. Anyway, you can tell Ruby that's where they're installed by setting the GEM_HOME environment variable.

    $ # assuming your gems are stored in ~/.gems
    $ GEM_HOME="$HOME/.gems" ruby my_program.rb
    

    If that works, then you might put it in your ~/.bashrc (there are a number of possible files this could go in, depending on your system)

提交回复
热议问题