50

After installing rvm, updating .gmrc file, updating rubygems and running gem install rails -v ">=3.1.0rc", I now seem to have a complete mess:

$ rails -v
/usr/local/lib/site_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find rails (>= 0) amongst [] (Gem::LoadError)
    from /usr/local/lib/site_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
    from /usr/local/lib/site_ruby/1.8/rubygems.rb:1182:in `gem'
    from /var/lib/gems/1.8/bin/rails:18

myhome@myhome-mini:~$ gem env

RubyGems Environment:
  - RUBYGEMS VERSION: 1.6.2
  - RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [i686-linux]
  - INSTALLATION DIRECTORY: /home/myhome/gems
  - RUBY EXECUTABLE: /home/myhome/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
  - EXECUTABLE DIRECTORY: /home/myhome/gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /home/myhome/gems
     - /usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gemhome" => "/home/myhome/gems"
     - "gempath" => ["/home/myhome/gems", "/usr/lib/ruby/gems/1.8"]
  - REMOTE SOURCES:
     - http://rubygems.org/
pdu
  • 10,295
  • 4
  • 58
  • 95
rigyt
  • 2,219
  • 3
  • 28
  • 40
  • I'm having this exact problem, but with the bundler gem. – Mark Aug 03 '11 at 21:27
  • Sorry I reinstalled Ubuntu on that machine so I can't comment on any of the solutions suggested..although actually I did try the sudo approach without success so I'll accept the remove ruby suggestion, thanks – rigyt Mar 08 '12 at 22:38

7 Answers7

85

I've had a similiar problem. Not sure if that helps you, but you might try to install gems with rvmsudo gem install [gemname] instead of just doing gem install [gemname] or sudo gem install [gemname].

I try to explain this a bit because of the upvotes:
This basically is a path issue. If you set up gems via gem install, they mostly likely will be in another directory (e.g. /usr/local/) compared to gems set up via bundler (where you can override it with --path). Using sudo may also set them up into another directory since sudo starts a subshell which has a different environment then. This is why you have rvmsudo.

If you want to see the differences, compare $PATH, $GEM_HOME, $GEM_PATH and $BUNDLE_PATH when echoing directly, with sudo and with rvmsudo.

pdu
  • 10,295
  • 4
  • 58
  • 95
  • 2
    This comment is especially useful for installing gems on travis-ci.org – badsyntax Jun 30 '13 at 09:48
  • i have this issue when creating my own gems and still developing them. In the main app i use path to reference the folder. when outside the application directory and I want to do something like rails -v I get this error saying it cannot find a custom gem I am developing. Any recommendations on a potential fix? – Spasm Oct 16 '14 at 01:25
33

I had to sudo gem install bundler to make it work again.

alex
  • 479,566
  • 201
  • 878
  • 984
Ace Suares
  • 346
  • 3
  • 2
6

I got a problem similar to this, there may be a compatible problem of rvm. I fixed by updating rvm to latest version:

curl -L https://get.rvm.io | bash -s stable --ruby

Then you should reload rvm or just open new terminal window. Then I reinstalled the bundler 'gem install bundler' and ran 'bundle install' as normal

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Huy Thai
  • 61
  • 1
  • 2
  • 3
    If you already have rvm installed and a newer version, this should do the same thing: `rvm get stable --auto` – jmervine Nov 12 '12 at 19:36
5
rvm rubygems current

did the trick for me.

Sv1
  • 2,414
  • 2
  • 18
  • 13
1

remove ruby first then

sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev

to install all needed lib then you could install ruby and rails

rvm install 1.9.3
rvm --default use 1.9.3
rvm gem install rails
Ish
  • 28,486
  • 11
  • 60
  • 77
naiteluo
  • 11
  • 1
0

I know this is a really old question but I just recently decided to move to RVM on a server I had setup a while ago and was having this same problem where gems were being installed in the wrong place and it was just messing everything up.

After a few hours of crawling through SO, I finally figured out that in my .gemrc file in my root folder, I had previously setup the gemhome: and gempath: variables and they were messing with the whole system.

After removing these lines, all my gems were working property.

Just thought I would post my answer in case someone was in the same position.

doz87
  • 591
  • 6
  • 15
0

I had pretty much the same message when trying to generate a controller after installing IntelliJ IDEA and the associated Plugin for Rail Dev. From my app directory I just executed bundle install and was then able to generate controllers again.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240