Running 'sudo gem list --local
' and 'gem list --local
' give me differing results. My gem path is set to my home folder and only contains the gems from 'gem list --local
'.
It's probably not good to have gems installed in different directories on my computer, so should I have the gem path set differently, and should I always use sudo
when installing something?
my ~/.profile
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
~/.bash_profile is empty.
You can install gems into a specific folder (example vendor/) in your Rails app using :
Related (for bundler users), if you want a lighter alternative to RVM which will put everything in a user-specific well known directory, I recommend using:
if you want to install gems to the same place that
will install them,
.gem/ruby/RUBYVERSION
in your homedir. (See the other comment on this question about--user-install
.)This will make the gems visible to
gem list
, uninstallable viagem uninstall
, etc. without needingsudo
access. Runnable scripts installed by gem or bundler can be put into your path by addingto your
$PATH
.gem
itself tells you about this if it isn't set when you dogem install --user-install
.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:
The reason why installing gems with
sudo
is worse than justgem install
is because it installs the gems for ALL USERS asroot
. 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 usingsudo
will cause all kinds of weirdness because each Ruby version you install throughRVM
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.
Better yet, put
--user-install
in your ~/.gemrc file so you don't have to type it every timeIn case you
add the following to your
.bash_profile
:Open a new tab in Terminal OR
source ~/.bash_profile
and you're good to go!will install your gem globally, i.e. it will be available to all user's contexts.