I recently upgraded to Ubuntu 9.04 and I have issues using gems.
I installed Ruby, Rubygems and Rails using apt-get.
The rails
command does work.
I then installed capistrano and other gems, such as heroku.
In order to do that, I used the command:
sudo gem install XXX
When I want to use the cap
command it does not work:
bash: cap: command not found
It is the same with the other gem commands.
Do I have something particular to do so that the gem commands work?
Best Answer
Where are my Gems?
You can find where your gems are stored using the
gem environment
command. For example:If you look at the "GEM PATHS:" section you can see that gems can be stored in two places on my laptop:
/usr/lib/ruby/gems/1.8
or in the.gem
directory in my home dir.You can also see that executables are stored in EXECUTABLE DIRECTORY which in this case is
/usr/bin
.Because
/usr/bin
is in my path this lets me runcap
,merb
,rails
etc.Updating your PATH
If for some reason your EXECUTABLE DIRECTORY isn't on your path (for example if it is /var/lib/gems/1.8/bin) then you need to update your PATH variable.
Assuming that you are using the bash shell. You can do this quickly for the current session by typing the following at the shell prompt; let's pretend that you want to add
/var/lib/gems/1.8/bin
to the path:and press return. That appends the new directory to the end of the current path. Note the colon between
$PATH
and/var/lib/gems/1.8/bin
To set the value for all sessions you will need to edit either your
.profile
or.bashrc
file and add the same line to the end of the file. I usually edit my.bashrc
file for no reason other than that's what I've always done. When finished, save the file and then refresh your environment by typing:at the shell prompt. That will cause the
.bashrc
to get reread.At any point you can check the current value of
$PATH
by typingat the shell prompt.
Here's a sample from one of my own servers, where my username is "chris" and the machine name is "chris-laptop":
My Gem won't load!
"Ruby gems won't load even though installed" highlights a common problem using multiple different versions of Ruby; Sometimes the Gem environment and Gem path get out of sync:
Any Ruby process here is looking only in one place for its Gems.
Look carefully at the output of gem environment:
This isn't the same path as returned by Gem.path:
It's hard to say what exactly caused
lib/ruby
to change tolib/ruby1.9
but most likely the developer was working with multiple Ruby versions. A quickmv
orln
will solve the problem.If you do need to work with multiple Ruby versions then you really should be using rvm.