how to install gems without sudo how to install gems without sudo ruby ruby

how to install gems without sudo


Use chown on the whole .rvm and .gem directories back to your user. You probably used sudo before and it screwed up permissions.

sudo chown -R username:group ~/.rvmsudo chown -R username:group ~/.gem

Of course, change username to your username and group to your group


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)


For Mac users, this works for me...

  1. Add GEM_HOME to your .bash_profile

For example, nano ~/.bash_profile and add export GEM_HOME=$HOME/.gem where the path is to your own Home folder

  1. Add the gem executables to your system path

Also in .bash_profile, add export PATH="$GEM_HOME/bin:$PATH"

Source: http://michaelehead.com/2016/02/06/installing-gems-without-sudo.html