7

When trying to update OpenSSL - I broke (seemingly) everything surrounding Ruby and Rails on my laptop. Even after uninstalling ruby and rails through gem uninstall and rvm removeI am still running into this error:

Drews-MacBook-Pro:bookstore drewwyatt$ rails server
bin/rails:3: undefined method `require_relative' for main:Object (NoMethodError)

Everything has been working fine for months until I went mucking around - the worse part is that I'm not even sure what I did to mess things up.

extra info

Drews-MacBook-Pro:bookstore drewwyatt$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]
Drews-MacBook-Pro:bookstore drewwyatt$ which ruby
/Users/drewwyatt/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
Drews-MacBook-Pro:bookstore drewwyatt$ rails -v
bin/rails:3: undefined method `require_relative' for main:Object (NoMethodError)
Drews-MacBook-Pro:bookstore drewwyatt$ which rails
/Users/drewwyatt/.rvm/rubies/ruby-2.0.0-p247/bin/rails
Drews-MacBook-Pro:bookstore drewwyatt$ 

update - installing without sudo

Drews-MacBook-Pro:~ drewwyatt$ gem install rails
Fetching: railties-4.0.0.gem (100%)
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /Users/drewwyatt/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks
Drews-MacBook-Pro:~ drewwyatt$ 
drewwyatt
  • 5,989
  • 15
  • 60
  • 106
  • This is really strange. Maybe you should go back system installed openssl. – Ismael Abreu Sep 21 '13 at 16:14
  • 1
    require_relative being undefined is usually a sign that you're on a lower ruby than 1.9. since that doesn't seem to be the problem, what rails version are you running? – Mike H-R Sep 21 '13 at 16:15
  • @MikeH-R Should be rails 4. When I reinstalled I just ran `sudo gem install rails` – drewwyatt Sep 21 '13 at 16:16
  • The stack trace tells it's running ruby 2.0.0 – Ismael Abreu Sep 21 '13 at 16:17
  • @IsmaelAbreu Yes, that is correct. Ruby 2, Rails 4 – drewwyatt Sep 21 '13 at 16:21
  • The `sudo` may well have lost enough of your environment to do something funny for the install (such as install it using your system Ruby). Try a `sudo gem uninstall rails`, then a `gem install rails`, *without* the `sudo`. – Neil Slater Sep 21 '13 at 17:04
  • @NeilSlater Just added an update - that's wht I had to use sudo last time. any ideas? – drewwyatt Sep 21 '13 at 18:25
  • It happened when I tried to run 'rails server' after installing a new version of jruby (1.7.4 to 1.7.5) in a different console. (I opened two consoles.) But it worked with reopening a console. – Nobu Oct 16 '13 at 18:52

5 Answers5

10

I fixed the problem by completely removing Rails, Ruby, and RVM altogether - then starting from scratch.

I don't remember all of the commands exactly, but it was something like:

sudo gem uninstall rails
sudo rvm remove 2.0
rvm implode
sudo chown -R drewwyatt: ~/.rvm/
rm -rf ~/.rvm
\curl -L https://get.rvm.io | bash -s stable --rails
rvm use 2.0
gem install rails
drewwyatt
  • 5,989
  • 15
  • 60
  • 106
  • 1
    This seems a bit heavy-handed as a starting place. I'd encourage people to start with the solution below and work to this answer if a simple `gem install rails` doesn't work, updating everything to 4.0.0 (especially true for Ruby/Rails noobs) – Zack Shapiro Oct 19 '13 at 17:06
10

This came up for me after installing rails with Rails Composer. Seems like a problem with RVM selecting the ruby version, the trick was to simply navigate out and back into the folder.

$ cd ..
$ cd myapp

tom
  • 718
  • 8
  • 15
6

I was able to resolve this problem by simply running gem install rails.

This problem occurred when I cloned a pre-existing Rails 4 app. I am using ruby-2.0.0-p317, and an RVM gemset specific to this app. I ran the initial bundle install, but then could not run rails console without getting the error.

After running gem install rails, which used the cached copy in my app's gemset, the problem was resolved. Don't ask my why!

platforms
  • 2,666
  • 1
  • 18
  • 23
  • 1
    Same deal with my answer. I feel like a lot of my "command line problems" end up being fixed in ways that make me think "not sure why that works, but thank god it did." – drewwyatt Oct 08 '13 at 15:37
  • This also appeared to resolve it for me as well with ruby `2.0.0-p0` and rails `4.0.0` – Brandon Buck Oct 15 '13 at 16:14
  • This did it for me. This should solve any weirdness if you're in the phase where you're juggling Ruby 1.9.x or Rails 3.x and upgrade to Ruby 2 and Rails 4 – Zack Shapiro Oct 19 '13 at 17:05
4

Try running bundle exec rails server instead of just rails server.

I was seeing this error because I had a conflicting version of the rails gem installed globally.

Prefixing commands with bundle exec ensures that you're using gems specified by your project's Gemfile.lock.

ncherro
  • 2,604
  • 2
  • 24
  • 20
0

Similar to @ncherro, I got this using ruby filename.rb. Running

bundle exec ruby filename.rb   

works.

Darby
  • 769
  • 1
  • 8
  • 26