Undefined method `require_relative 'for main: Object (NoMethodError)

When I try to update OpenSSL - I broke (apparently) everything around Ruby and Rails on my laptop. Even after removing rubies and rails through gem uninstall and rvm remove I still encounter this error:

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

Everything worked fine for several months until I cheated - the worst part is that I'm not even sure what I did to mess things up.

Additional Information

 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 - install 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$ 
+7
ruby ruby-on-rails macos
source share
5 answers

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

I don’t remember all 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 
+10
source share

This came up to me after installing rails with Rails Composer. It seems like the problem with choosing RVM in the ruby ​​version, the trick was to just go and go back to the folder.

$ cd ..
$ cd myapp

+10
source share

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

This problem arose when I cloned a pre-existing Rails 4 application. I use ruby-2.0.0-p317 and RVM gemset specific to this application. I ran the initial bundle install , but could not start the rails console without receiving an error.

After running gem install rails , which used a cached copy in my gemset application, the problem was resolved. Do not ask me why!

+6
source share

Try running bundle exec rails server instead of rails server .

I saw this error because I had a conflicting version of rails gem installed globally.

The prefix commands with bundle exec ensure that you use the gems specified by your Gemfile.lock project.

+4
source share

Like @ncherro, I got this using ruby ​​filename.rb. Performance

 bundle exec ruby filename.rb 

work.

0
source share

All Articles