RVM – Using rvmsudo instead of sudo

There are times when you need to run a ruby related command to install something, e.g. “bundle install” or “gem install gem-name”. If you are an rvm managed ruby version, then it is bad/messy practice to do this. because doing so will install the gem system-wide, rather then ruby version level. This all comes down to an environment variable called “rvm_path”. When using sudo, path no longer becomes available. That’s why to get around this, we use rvmsudo instead, which retains the user’s environment data while in privileged mode

[sher@puppetmaster ~]$ env | grep "^rvm_path"
[sher@puppetmaster ~]$ sudo env | grep "^rvm_path"      # notice that there's no match here.
[sher@puppetmaster ~]$ rvmsudo env | grep "^rvm_path"
[sher@puppetmaster ~]$

Hence the gem is installed system wide.