undefined method `require_relative' for main:Object (NoMethodError) - ruby-on-rails

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$

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

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

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!

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.

Similar to #ncherro, I got this using ruby filename.rb. Running
bundle exec ruby filename.rb
works.

Related

installing rails in rbenv with an old ruby

I'm working on a project in ruby 2.1.10. it should be using rails 4.0.13.
I'm using rbenv.
I've installed everything, I believe. I ran bundle install for the project. eventually I got it to run.
However, now I get:
turlingdrome$ rails
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
turlingdrome$ gem install rails -v 4.0.13
Successfully installed rails-4.0.13
Parsing documentation for rails-4.0.13
Done installing documentation for rails after 1 seconds
1 gem installed
turlingdrome$ which rails
/Users/brianp/.rbenv/shims/rails
turlingdrome$ rails -v
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
turlingdrome$ ruby -v
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin16.0]
in case it matters, I'm on a mac running 10.12.6
ETA from comment:
turlingdrome$ bundle exec rails -v
Rails 4.0.13
so, bundle exec lets me run rails. rbenv exec rails seems to work too.
So, the problem seems to be in the shim!
Rehash the shims:
rbenv rehash
Now you should be able to run only rails without bundle exec or rbenv exec.

Ruby on Rails installation ubuntu

After using rails a single use, my rails seem to break. It gives me an error:
/home/username/.rbenv/versions/2.2.3/bin/rails:23:in `load': cannot load such file -- /home/dasith/.rvm/gems/ruby-2.3.0/gems/rails-4.2.6/bin/rails (LoadError)
from /home/dasith/.rbenv/versions/2.2.3/bin/rails:23:in `<main>'
To make it work again, I have to run these commands:
rvm gemset create gemset_name # create a gemset
rvm ruby_version#gemset_name # specify Ruby version and our new gemset
gem install rails -v rails_version # install specific Rails version
Fixed it. It was an permission issue.
sudo chown -R username /home/username/.rbenv

rails -v Get different ERRORS -

I'm really frustrated two day trying to work with rails for first time but I got many errors right now when I try to get the rails version got te next:
➜ first_app $ pwd
/Users/ChrispazDev/rails_projects/first_app/first_app
➜ first_app $ rails -v
Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub rails` to work around a system/bundle conflict.
Rails 4.2.3
➜ first_app $ cd ..
➜ first_app $ rails -v
/Users/ChrispazDev/.rvm/gems/ruby-2.2.1#update3tutorial/bin/rails:23:in `load': cannot load such file -- /Users/ChrispazDev/.rvm/gems/ruby-2.2.1#update3tutorial/gems/rails-4.2.3/bin/rails (LoadError)
from /Users/ChrispazDev/.rvm/gems/ruby-2.2.1#update3tutorial/bin/rails:23:in `<main>'
from /Users/ChrispazDev/.rvm/gems/ruby-2.2.1#update3tutorial/bin/ruby_executable_hooks:15:in `eval'
from /Users/ChrispazDev/.rvm/gems/ruby-2.2.1#update3tutorial/bin/ruby_executable_hooks:15:in `<main>'
➜ first_app
Sorry if it's something stupid but I'm really lost.
Mac OS 10.10.3
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
Regards.
It appears that the install of Rails is messed up. The last error message comes from when you were at the path /Users/ChrisapzDev/rails_projects/first_app compared with the original message inside a sub-directory to this path.
Additionally notice that you have RVM installed so you may need to
Test the path that is being used for the invocation of rails using explicit ./rails -v to see what happens
Clean out the RVM Gemset rvm gemset empty
Reinstall rails in the context of the gemset you have allocated via RVM.
It is because of RVM, your ruby versions are messed ( Your system ruby, and ruby you installed with rvm). There is no need to uninstall RVM as it will help you to switch between your ruby versions.
Try using below code
rvm use system // for using system ruby
rvm use x.x.x // Here x.x.x is version of ruby
as rvm use 2.2.2
May be this tutorial will help you .

Failed to install Rails on yosemite

I installed Ruby via rbenv. Currently, my pc has ruby 2.1.2p95 version installed. I have just started development in rails. So, don't know much about it.
But, I get some kind of error when I installed it.
$gem install rails -v 4.2.0
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
Did you run rbenv rehash after installing that version of ruby? Perhaps your PATH is pointing to the wrong gem command?
I've run into something similar.
Try
xcode-select --install
Than perhaps give this a go if it still doesn't work:
rbenv uninstall 2.1.2p95
rbenv install 2.1.2p95

Installing Ruby on Rails on Mac

To install RoR on my Mac (v10.9.2), I decided to follow the instructions for Ruby 1.9.2 here: https://stackoverflow.com/a/8464619/2278546
"rvm install 1.9.2" was taking too long, so based on suggestions on SO, I used "rvm requirements" to install each of the requirements individually with macports. I then executed "rvm install 1.9.2" and it ran much faster.
When I tried to execute "gem install rail", I got an error message saying
activesupport requires Ruby version >= 1.9.3
As a result, I went back and tried again with 1.9.3:
rvm install 1.9.3
rvm --default 1.9.3
gem update
gem install rails
This time, during the rails install command, the process got stuck installing the documentation for rails. I decided to interrupt and run this instead:
gem install --no-ri --no-rdoc rails
This worked! I ran the following:
rails new pong; cd pong; rails generate controller welcome index
The last command in that string gave me the following error:
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:17:in
fiddle_func': uninitialized constant Spring::SID::DL (NameError)
from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:30:in
sid' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/sid.rb:39:in
pgid' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:78:in
set_pgid' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:34:in
boot' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/server.rb:14:in
boot' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:36:in
block in boot_server' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:34:in
fork' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:34:in
boot_server' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/run.rb:18:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/command.rb:7:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/rails.rb:23:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client/command.rb:7:in
call' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/client.rb:26:in
run' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/bin/spring:48:in
<top (required)>' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/binstub.rb:11:in
load' from
/Users/me/.rvm/gems/ruby-1.9.3-p545/gems/spring-1.1.2/lib/spring/binstub.rb:11:in
<top (required)>' from /Users/me/Coding/pong/bin/spring:16:in
require' from /Users/me/Coding/pong/bin/spring:16:in <top
(required)>' from bin/rails:3:inload' from bin/rails:3:in `'
Based on suggestions read here and here and elsewhere, I decided to try with a different compiler:
port install gcc46
CC=`which gcc-mp-4.6`
rvm reinstall 1.9.3
gem install
rvm reinstall 1.9.3
Same problem with this installation as well.
I suspect interrupting those builds might have left things in a bad state. First off, uninstall 1.9.2. 1.9.3-p545 is the oldest supported version, as of now at least.
Next, uninstall the gem 'spring-commands-rspec' and run a gem pristine -all. Then do another bundle install. FWIW, I am able to run spring on my 10.9.2 macbook. You may have to reinstall the xcode command line tools if your gcc is giving you issues.
Beyond all that, you don't need spring to run a rails app. It's primarily a helper during development and testing. Once you get things cleaned up, I would just remove the thing from your Gemfile until you actually need it.
I was able to get things running by mixing #Andrew's advice with some common sense...
I first cleaned up the mess I had made:
sudo rvm remove 1.9.2
sudo rvm remove 1.9.3
sudo rvm remove 1.9.3-p545
sudo gem uninstall spring-commands-rspec
sudo gem pristine -a
sudo port uninstall rvm
I then reinstalled rvm
sudo port install rvm
and reinstalled Ruby 1.9.3 with rails:
sudo rvm install 1.9.3
sudo gem update
sudo gem install --no-ri --no-rdoc rails
The problem as described above still occurred.
I then remembered that I had received the following message when installing Ruby (confirming Andrew's comment):
WARNING: Please be aware that you just installed a ruby that is no
longer maintained (2014-02-23), for a list of maintained rubies visit:
http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering
Please consider upgrading to ruby-2.1.1 which will have all of the
latest security patches.
So, I cleaned up again:
sudo rvm remove 1.9.3
sudo rvm remove 1.9.3-p545
sudo gem uninstall spring-commands-rspec
sudo gem pristine -a
Then, I tried installing Ruby 2.1.1 and Rails:
sudo rvm install 2.1.1
sudo gem update
sudo gem install --no-ri --no-rdoc rails
This time, I got no errors when I tried to run
rails new pong; cd pong; rails generate controller welcome index
This is not an ideal answer because I still couldn't get 1.9.3 to work, but it fits my purposes (I think). Anyone have any theories explaining why 1.9.3 doesn't work?
Thanks,
Grasswistle

Resources