Contrary to all the other posts I suggest NOT using sudo
when installing gems.
Instead I recommend you install RVM and start a happy life with portable gem homes and different version of Ruby all living under one roof.
For the uninitiated, from the documentation:
RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments and sets of gems.
The reason why installing gems with sudo
is worse than just gem install
is because it installs the gems for ALL USERS as root
. This might be fine if you're the only person using the machine, but if you're not it can cause weirdness.
If you decide you want to blow away all your gems and start again it's much easier, and safer, to do so as a non-root user.
If you decide you want to use RVM
then using sudo
will cause all kinds of weirdness because each Ruby version you install through RVM
has its own GEM_HOME.
Also, it's nice if you can make your development environment as close to your production environment as possible, and in production you'll most likely install gems as a non-root user.
sudo gem install rails
instead ofgem install rails
. – Dennissudo
is a loaded gun pointed toward your foot. Using it without understanding what it does and how it can affect your system is like pulling the trigger with your eyes closed. You might shoot a hole in your foot, you might not, but either way you don't want to run the risk unless you know how to undo the damage. Usingsudo
writes into the system-owned Ruby, which, on Mac OS, was installed by Apple for their own uses. We can piggyback on it, but changing the wrong thing can break their code. That's why we install from source or use something else to install where we can safely tweak it. – the Tin Man