主要的未定义方法`require_relative':Object(NoMethodError)

时间:2022-05-03 23:52:40

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:

在尝试更新OpenSSL时 - 我在笔记本电脑上打破了(似乎)Ruby和Rails的所有内容。即使卸载ruby和rails通过gem uninstall和rvm removeI仍然遇到此错误:

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

更新 - 没有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$ 

5 个解决方案

#1


10  

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

我通过完全删除Rails,Ruby和RVM来解决问题 - 然后从头开始。

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

#2


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.

在使用Rails Composer安装rails之后,我想到了这一点。看起来像RVM选择ruby版本的问题,诀窍是简单地导航并返回到文件夹。

$ cd ..
$ cd myapp

$ cd .. $ cd myapp

#3


6  

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

我只需运行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.

当我克隆预先存在的Rails 4应用程序时发生此问题。我正在使用ruby-2.0.0-p317,以及一个特定于此应用程序的RVM gemset。我运行了初始捆绑安装,但是在没有收到错误的情况下无法运行rails console。

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

运行gem install rails后,我在应用程序的gemset中使用了缓存副本,问题解决了。不要问我为什么!

#4


4  

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

尝试运行bundle exec rails服务器而不仅仅是rails服务器。

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

我看到这个错误,因为我在全局安装了rails gem的冲突版本。

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

使用bundle exec的前缀命令可确保您使用项目的Gemfile.lock指定的gem。

#5


0  

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

与@ncherro类似,我使用ruby filename.rb得到了这个。运行

bundle exec ruby filename.rb   

works.

#1


10  

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

我通过完全删除Rails,Ruby和RVM来解决问题 - 然后从头开始。

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

#2


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.

在使用Rails Composer安装rails之后,我想到了这一点。看起来像RVM选择ruby版本的问题,诀窍是简单地导航并返回到文件夹。

$ cd ..
$ cd myapp

$ cd .. $ cd myapp

#3


6  

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

我只需运行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.

当我克隆预先存在的Rails 4应用程序时发生此问题。我正在使用ruby-2.0.0-p317,以及一个特定于此应用程序的RVM gemset。我运行了初始捆绑安装,但是在没有收到错误的情况下无法运行rails console。

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

运行gem install rails后,我在应用程序的gemset中使用了缓存副本,问题解决了。不要问我为什么!

#4


4  

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

尝试运行bundle exec rails服务器而不仅仅是rails服务器。

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

我看到这个错误,因为我在全局安装了rails gem的冲突版本。

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

使用bundle exec的前缀命令可确保您使用项目的Gemfile.lock指定的gem。

#5


0  

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

与@ncherro类似,我使用ruby filename.rb得到了这个。运行

bundle exec ruby filename.rb   

works.