ItGo.me Focus on IT Recommend

Home > ruby on rails - How do I use gems with Ubuntu?

ruby on rails - How do I use gems with Ubuntu?

up vote 76 down vote favorite 52 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? ruby-on-rails ruby ubuntu rubygems capistrano
  edited Feb 4 '12 at 0:52 the Tin Man 116k 24 145 213 asked May 26 '09 at 8:55 Arthur 2,711 7 32 71      isn't this question more suitable asked in superuser.com? –  Thiago Diniz Oct 15 '10 at 3:56      @ThiagoDiniz or in askubuntu.com? –  Eliran Malka Nov 20 '13 at 15:39



 |  5 Answers

up vote 138 down vote ---Accepted---Accepted---Accepted---

Where are my Gems? You can find where your gems are stored using the gem environment command. For example: chris@chris-laptop:~$ gem environment

RubyGems Environment:

- RUBYGEMS VERSION: 1.3.2

- RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]

- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8

- RUBY EXECUTABLE: /usr/bin/ruby1.8

- EXECUTABLE DIRECTORY: /usr/bin

- RUBYGEMS PLATFORMS:

- ruby

- x86-linux

- GEM PATHS:

- /usr/lib/ruby/gems/1.8

- /home/chris/.gem/ruby/1.8

- GEM CONFIGURATION:

- :update_sources => true

- :verbose => true

- :benchmark => false

- :backtrace => false

- :bulk_threshold => 1000

- REMOTE SOURCES:

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 run cap, 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: export PATH=$PATH:/var/lib/gems/1.8/bin

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: bash

at the shell prompt. That will cause the .bashrc to get reread. At any point you can check the current value of $PATH by typing echo $PATH

at 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": chris@chris-laptop:~$

chris@chris-laptop:~$ echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

chris@chris-laptop:~$

chris@chris-laptop:~$ export PATH=$PATH:/var/lib/gems/1.8/bin

chris@chris-laptop:~$

chris@chris-laptop:~$ echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin

chris@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: rb(main):003:0> Gem.path

=> ["/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"]

irb(main):004:0> exit

Any Ruby process here is looking only in one place for its Gems. :~/$ gem env

RubyGems Environment:

- RUBYGEMS VERSION: 1.3.7

- RUBY VERSION: 1.9.1 (2009-05-12 patchlevel 129) [x86_64-linux]

- INSTALLATION DIRECTORY: /opt/ruby1.9/lib/ruby/gems/1.9.1

- RUBY EXECUTABLE: /opt/ruby1.9/bin/ruby1.9

- EXECUTABLE DIRECTORY: /opt/ruby1.9/bin

- RUBYGEMS PLATFORMS:

- ruby

- x86_64-linux

- GEM PATHS:

- /opt/ruby1.9/lib/ruby/gems/1.9.1

- /home/mark/.gem/ruby/1.9.1

- GEM CONFIGURATION:

- :update_sources => true

- :verbose => true

- :benchmark => false

- :backtrace => false

- :bulk_threshold => 1000

- REMOTE SOURCES:

- http://rubygems.org/

Look carefully at the output of gem environment:

- GEM PATHS:

- /opt/ruby1.9/lib/ruby/gems/1.9.1

This isn't the same path as returned by Gem.path: [&

Recommend:ruby on rails - How can I continue to use Accurev with Capistrano 3

to upgrade to Capistrano 3, but it seems that the Accurev SCM module has been removed. Is there a way I can continue to use AccuRev and deploy with Capistrano 3 deploy.rb piece set :scm, :accurev Deployment error cap aborted!LoadError:

quot;/opt/ruby1.9/lib/ruby1.9/gems/1.9.1"]

It's hard to say what exactly caused lib/ruby to change to lib/ruby1.9 but most likely the developer was working with multiple Ruby versions. A quick mv or ln will solve the problem. If you do need to work with multiple Ruby versions then you really should be using rvm.
  edited Feb 4 '12 at 0:50 the Tin Man 116k 24 145 213 answered May 26 '09 at 10:23 Chris McCauley 15.3k 6 30 56      How can I edit my $PATH so that it includes the two directory where the gems are installed ? Thanks –  Arthur May 26 '09 at 10:42      I did that : sudo ln -s /var/lib/gems/1.8/gems/capistrano-2.5.5/bin/cap /usr/local/bin/cap ln: creating symbolic link `/usr/local/bin/cap': File exists But it does not work ! It still get : bash: cap: command not found Here is my $PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin‌​:/usr/games:/opt/rea‌​l/RealPlayer:/var/li‌​b/gems/1.8:/home/art‌​hur/.gem/ruby/1.8 –  Arthur May 26 '09 at 11:11      Now it works. I changed the path to: /var/lib/gems/1.8/bin:/home/arthur/.gem/ruby/1.8/bin –  Arthur May 26 '09 at 12:42      Is there a way to change the EXECUTABLE_DIRECTORY to something more standard, like /usr/bin or /usr/local/bin? Adding /var/lib/gems/1.8/bin to my path doesn't sit well, particularly since it has a version number in it. –  Kief Jul 14 '10 at 15:09      When I wanted to change that on a system level I had to change that at /etc/environment –  dolzenko Jul 22 '10 at 21:29  |  show 1 more comment up vote 5 down vote As noted by @Chris you need to add the gems environment to your path. You can do this by: echo 'export PATH=$PATH:/var/lib/gems/1.8/bin' | tee --append ~/.bashrc


  answered Aug 8 '11 at 20:09 Adam Greenhall 1,288 3 16 27



 |  up vote 3 down vote The folder in which gems are stored must be on your PATH, for example mine is: /home/victor/.gem/ruby/1.8/bin Check your path by typing echo $PATH


  answered May 26 '09 at 9:07 victor hugo 25.1k 10 53 73 1   Thanks for your answer Here is the content of ~/.gem/ruby/1.8/bin : activerecord-2.3.2 activesupport-2.3.2 heroku-0.9.1 json-1.1.6 rails-2.3.2 When I install capistrano from my home folder ~, it does not go in this folder. Furthermore, the heroku gem is in the right folder but the heroku command does not work. Also here is what the $PATH command returns: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin‌​:/usr/games –  Arthur May 26 '09 at 9:14      Does your rails gem work? Please add your folder ~/.gem/ruby/1.8/bin to the path and give a try –  victor hugo May 26 '09 at 9:43      How can I do that ? I don't know the shell command Thanks –  Arthur May 26 '09 at 9:53      I asked a question in order to know how to edit the $PATH: stackoverflow.com/questions/910088/how-can-i-edit-the-path- on-linux –  Arthur May 26 '09 at 10:57



 |  up vote 1 down vote It seens that when installing rubygems, now in ubuntu 9.04, I have this problem. I noticed that in "gem environment" the executable directory is "/var/lib/gems/1.8/bin", instead of "/usr/bin"... This is a problem with rubygems or with ubuntu 9.04?? The solution that I encountered is to add "/var/lib/gems/1.8/bin" to my $PATH doing this: export PATH=$PATH:/var/lib/gems/1.8/bin But it don't is saved... how can I save my path? Thanks... Resolvi: coloquei o export PATH=$PATH:/var/lib/gems/1.8/bin no ~/.bashrc! =]
  edited May 27 '09 at 1:04 answered May 27 '09 at 0:02 Rafael Souza 2   To save the path, check out the other question I asked: stackoverflow.com/questions/910088/… –  Arthur May 27 '09 at 9:55

 |  up vote 0 down vote mkmf is part of the ruby1.9.1-dev package. This package contains the header files needed for extension libraries for Ruby 1.9.1. You need to install the ruby1.9.1-dev package by doing: sudo apt-get install ruby1.9.1-dev
  answered Apr 2 '13 at 11:36 Sohan 1,081 1 10 29

 | 

Recommend:ruby on rails - How to use Capistrano with Aptana Studio 3

te at /home/admin/www/webstudio on my host I'm trying so hard to get it "visible" at: www.web-studio.fi Then I try to use Capistrano to publish my website::: I right-click on my WEBSTUDIO folder Select PUBLISH >> RUN WEB DEPLOYMENT WIZARD I

up vote 76 down vote favorite 52 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

oriUlr:http://stackoverflow.com/questions/909673/how-do-i-use-gems-with-ubuntu

------splitte line----------------------------