views:

42

answers:

2

Hi,

I am new to ruby. I've just installed Ruby and Rails on my fresh Ubuntu OS.

I created a new rails project based on the screencast from rubyonrail websites. http://media.rubyonrails.org/video/rails_blog_2.mov

However, when executing ruby script/server, I am getting this error:

Missing the Rails gem. Please gem install -v= rails, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.

I followed the instruction, by commenting it out, but still getting the same error.

I am using Ruby v1.9.1, Rails v2.3.8

h@ubuntu:~/ruby/code/blog$ which ruby

/usr/local/bin/ruby

h@ubuntu:~/ruby/code/blog$ which gem

/usr/local/bin/gem

h@ubuntu:~/ruby/code/blog$ which rails

/usr/bin/rails

Please advice..

Thanks..

+1  A: 

have you tried to edit

YOUR_RAILS_PROJECT_DIR/config/environment.rb

look for RAILS_GEM_VERSION and change the version according to the one you installed. so in this case it will be:

RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
apeacox
yes, i did.this is what i got:RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSIONMy rail version is 2.3.8Am i missing something here?
Hery
have you installed other versions of ruby, such as 1.8.7? how did you install rubygems under ubuntu? the *correct* way should be to install ruygems from original package, not using the one from repository.
apeacox
i downloaded the zip file from the site, from console, i run "ruby setup.rb" as i am aware of, i only installed 1.9.1.
Hery
if "gem which rails" returned an error, then there's something wrong finding the install path of rails gem. try to launch "gem which <another installed gem>" just to see the behaviour. also look in "/usr/lib/ruby/gems/1.9.1/" to see what gems are present
apeacox
i tried "gem which rake", and i got: /usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb. Also, I couldn't locate 1.9.1 under that folder. There is only version 1.8. Kinda weird, because i didn't install 1.8.seems that the installation folder is completely a mess..
Hery
why you have ruby installed in /usr/local/* ? it should be in /usr/*. btw that's not the main problem :Pone last question: how did you install ruby?
apeacox
honestly, i've no idea as im new to *nix system as well. How did I install ruby? "sudo apt-get install ruby1.9.1"
Hery
If you haven't any constraint about ruby versions in use, I suggest you to install ruby 1.8.7 because 1.9.1 it's not yet mature.uninstall EVERY reference to ruby 1.9.1 ("sudo apt-get remove --purge ruby1.9.1", then look for eventual files remained in /usr/lib/ruby or /usr/local/ruby/*,etc...). clean your home (eg: .gem/ directory).then: - sudo apt-get install ruby rubygems ruby-dev rdoc ri irb libopenssl-ruby - download and install (with sudo) rubygems from official site (this will overwrite the existing from repository) - sudo gem install rails <other_gems_you_need>this should work ;)
apeacox
continuing from last comment: if you really need ruby 1.9.1, then you could use RVM (http://rvm.beginrescueend.com/) installing whatever version of ruby directly in your home, without issues. for example, I'm using RubyEnterprise and Rails3beta4 using RVM. but on my system is installed ruby 1.8.7 and rails 2.3.x ;)
apeacox
thanks mate.. it works.. appreciate your help. it has been tough for me, as I need to learn the OS as well.. in the end, i uninstalled 1.9.1 and I am happy with 1.8.7 :)
Hery
glad to help you ;)
apeacox
+1  A: 

Hmmm...

Try these, see if you can get some ideas:

$ ruby -r rubygems -e "p Gem.path"
$ gem which rails
$ gem list rails

This should give you the path that require looks for gems, the path where gem has installed your Rails (I actually had a box with two different Ruby installations where things got funny and ruby and gem had a different idea of where gems are), and which version of Rails gem has.

Amadan
$ ruby -r rubygems -e "p Gem.path"returned: ["/home/h/.gem/ruby/1.9.1", "/usr/lib/ruby/gems/1.9.1"]$ gem which railsreturned: ERROR: Can't find ruby library file or shared library rails$ gem list railsreturned: rails (2.3.8)Seems it couldn't locate ruby library? Not sure what is that.. :(
Hery
If you installed only with `ruby setup.rb` (without `sudo`), then it's probably installed in your home (and the repository might not be at `/usr/lib`). Besides, why are you installing from an installer on a Ubuntu box? Wouldn't `sudo apt-get install ruby1.9` be easier/better/safer? Anyway - try one more command: `gem list -d rails` - if it goes without an error (`gem list rails` does, so I'm hopeful), it will show you where you actually installed it.
Amadan
executing "gem list -d rails" returned rails (2.3.8) Author: David Heinemeier Hansson Rubyforge: http://rubyforge.org/projects/rails Homepage: http://www.rubyonrails.org Installed at: /usr/lib/ruby/gems/1.8
Hery
i might screw everything up. how to clean my existing installation and do the fresh one.. ? sorry i kinda new as well to nix system..
Hery
There you go - It's installed (who knows why) at `/usr/lib/ruby/gems/1.8`, but the search path is `/usr/lib/ruby/gems/1.9.1`. Also, see me being silly thinking you installed Ruby with `setup.rb` :) Anyway, try `sudo rm -rf /usr/lib/ruby/gems/1.8; sudo gem install rails` to reinstall Rails, see what pops up.
Amadan
i tried what u recommend to do, but getting the same result."sudo gem install rails" installed ruby 1.8 in the same path. While, ruby -r rubygems -e "p Gem.path" still returns: ["/home/h/.gem/ruby/1.9.1", "/usr/lib/ruby/gems/1.9.1"].. Is there anyway to update the gem path?
Hery