简体   繁体   English

如何从头开始我的 Ruby 环境?

[英]How can I start my Ruby environment from scratch?

I've been trying to upgrade my rails environment on my MacBook and I've messed something up, but I'm not sure what.我一直在尝试升级我的 MacBook 上的 Rails 环境,但我搞砸了,但我不确定是什么。 Is it possible to completely remove RVM, Ruby and Rails and start from scratch?是否可以完全移除 RVM、Ruby 和 Rails 并从头开始? I'm quite confused at how this is all supposed to work.我对这一切应该如何工作感到很困惑。

I've currently got Ruby 1.8.7 and 1.9.2 installed via RVM.我目前已经通过 RVM 安装了 Ruby 1.8.7 和 1.9.2。 I had rails upgraded to 3.0.9 but it refuses to work now, citing some error with rake.我已将 rails 升级到 3.0.9,但它现在拒绝工作,理由是 rake 出现了一些错误。

/Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in to_specs': Could not find rails (>= 0) amongst [rake-0.8.7, rake-0.8.7, rubygems-update-1.8.5] (Gem::LoadError) from /Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in to_spec' from /Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:1182:in gem' from /Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/bin/rails:18:in ' /Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in to_specs': Could not find rails (>= 0) amongst [rake-0.8.7, rake-0.8.7, rubygems-update-1.8.5] (Gem::LoadError) from /Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in to_spec' 来自 /Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb: 1182:in gem' from /Users/Moshe/.rvm/rubies/ruby-1.9.2-p180/bin/rails:18:in '

What can I do to fix the situation?我能做些什么来解决这种情况? I'd like to revert to the version of ruby that came with my Mac.我想恢复到我的 Mac 附带的 ruby 版本。

( Edit: I'm on Snow Leopard 10.6.8) 编辑:我在 Snow Leopard 10.6.8 上)

Edit2:编辑2:

I've now gotten rvm to run ruby 1.9.2 and rails 3.0.9 However, trying to boot the server using rails server returns the following:我现在已经让 rvm 运行 ruby 1.9.2 和 rails 3.0.9 但是,尝试使用rails server启动服务器会返回以下内容:

AppMachineMobile:hello Moshe$ rails server AppMachineMobile:你好 Moshe$ rails 服务器

=> Booting WEBrick => 启动 WEBrick

=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000 => Rails 3.0.9 应用程序开始在http://0.0.0.0:3000上开发

=> Call with -d to detach => 使用 -d 调用以分离

=> Ctrl-C to shutdown server => Ctrl-C 关闭服务器

Exiting退出

/Users/Moshe/Development/Ruby/hello/config/initializers/new_rails_defaults.rb:14: undefined method `generate_best_match=' for ActionDispatch::Routing:Module (NoMethodError) /Users/Moshe/Development/Ruby/hello/config/initializers/new_rails_defaults.rb:14:ActionDispatch::Routing:Module 的未定义方法“generate_best_match=”(NoMethodError)

from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in `load'来自 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in `load'

from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in `load'来自 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in `load'

from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'来自 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'

from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in `new_constants_in'来自 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in `new_constants_in'

from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'来自 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in `load_dependency'

from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in `load'来自 /Library/Ruby/Gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in `load'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/engine.rb:201来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/engine.rb:201

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/engine.rb:200:in `each'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/engine.rb:200:in `each'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/engine.rb:200来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/engine.rb:200

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `run_initializers'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `run_initializers'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `send'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `send'

from /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'来自 /Library/Ruby/Gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'

from /Users/Moshe/Development/Ruby/hello/config/environment.rb:5来自 /Users/Moshe/Development/Ruby/hello/config/environment.rb:5

from /Users/Moshe/Development/Ruby/hello/config.ru:3:in `require'来自 /Users/Moshe/Development/Ruby/hello/config.ru:3:in `require'

from /Users/Moshe/Development/Ruby/hello/config.ru:3来自 /Users/Moshe/Development/Ruby/hello/config.ru:3

from /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'来自 /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'

from /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'来自 /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'

from /Users/Moshe/Development/Ruby/hello/config.ru:1:in `new'来自 /Users/Moshe/Development/Ruby/hello/config.ru:1:in `new'

from /Users/Moshe/Development/Ruby/hello/config.ru:1来自 /Users/Moshe/Development/Ruby/hello/config.ru:1

I would try to start from scratch.我会尝试从头开始。 Check which rvms you have installed:检查您安装了哪些 rvms:

$rvm list

and you should get something like this:你应该得到这样的东西:

rvm rubies

   jruby-1.5.5 [ x86_64-java ]
   ree-1.8.7-2010.02 [ x86_64 ]
   ruby-1.8.6-p399 [ x86_64 ]
   ruby-1.8.7-p299 [ x86_64 ]
=> ruby-1.8.7-p302 [ x86_64 ]
   ruby-1.9.2-p0 [ x86_64 ]

Do a rvm uninstall on each piece:对每个部分执行 rvm 卸载:

$rvm uninstall 1.8.7
$rvm uninstall 1.9.2

Install Ruby 1.8.7:安装 Ruby 1.8.7:

$ rvm install 1.8.7

Install latest Ruby 1.9.2:安装最新的 Ruby 1.9.2:

$ rvm install 1.9.2

Set your default (or 1.8.7 if u want that):设置你的默认值(或者 1.8.7,如果你想要的话):

$ rvm use 1.9.2 --default

Install PostgreSQL and SQLite gems (assume snow leopard):安装 PostgreSQL 和 SQLite gems(假设是雪豹):

$ env ARCHFLAGS="-arch x86_64" gem install pg sqlite3-ruby

Install Rails 3 (includes Bundler):安装 Rails 3(包括 Bundler):

$ gem install rails

If you are in a rails 2x project:如果您在 rails 2x 项目中:

$rvm use 1.8.7

If you are in a rails 3 project:如果您在 rails 3 项目中:

$rvm use 1.9.2

When you are in each rvm, load the gems associated to the project via 'bundle install' if you are using bundler, or 'rake gems:install' if you have everything dumped into your environment.rb当您在每个 rvm 中时,如果您使用的是 bundler,则通过“bundle install”加载与项目关联的 gem,如果您将所有内容都转储到 environment.rb 中,则通过“rake gems:install”加载

rm -rf .rvm .rvmrc

then delete the.rvmrc files in your project directory if you want to be sure you start from scratch.如果您想确保从头开始,请删除项目目录中的 .rvmrc 文件。

Unless you have installed a system wide ruby besides installing one via rvm you dont have a "ruby" command any more, until you reinstall rvm again.除非您已经安装了系统范围的 ruby 除了通过 rvm 安装一个之外,否则您将不再有“ruby”命令,直到您再次重新安装 rvm。

So:所以:

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

to reinstall rvm.重新安装rvm。 Now everything should be back to default install.现在一切都应该恢复到默认安装。

I did not remove any.rvm and.rvmrc file.我没有删除任何.rvm 和.rvmrc 文件。 But my problem has been solved.但是我的问题已经解决了。 I dont know how it has been solved.我不知道它是如何解决的。 But what step I did, I am telling you.但是我做了什么,我告诉你。 First I used unstable version of rails gem in my Gemfile.首先,我在我的 Gemfile 中使用了不稳定版本的 rails gem。 That why problem is happening.这就是为什么会出现问题。

gem 'rails', :path => '/home/user/life/rails'  #this is an unstable rails 4.0.0 beta

 #gem 'rails', '3.2.8' 

user@sandip:~/life/samplelogin$ rails c
/home/user/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find railties (>= 0) amongst [activerecord-deprecated_finders-0.0.1, arel-3.0.2, atomic-1.0.1, builder-3.1.4, bundler-1.2.3, bundler-1.2.3, erubis-2.7.0, hike-1.2.1, i18n-0.6.1, json-1.7.5, mail-2.5.3, mime-types-1.19, minitest-4.3.3, multi_json-1.5.0, mysql2-0.3.11, polyglot-0.3.3, rack-1.4.1, rack-test-0.6.2, rake-10.0.3, rake-0.9.2, rdoc-3.12, sprockets-2.8.2, sprockets-rails-2.0.0.rc1, thor-0.16.0, thread_safe-0.1.0, tilt-1.3.3, treetop-1.4.12, tzinfo-0.3.35] (Gem::LoadError)
    from /home/user/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from /home/user/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
    from /home/user/.rvm/gems/ruby-1.9.3-p362/bin/rails:18:in `<main>'

Then next step what i did, I just comment the gem from local folder.然后下一步我做了什么,我只是从本地文件夹中评论 gem。

 #gem 'rails', :path => '/home/user/life/rails'  #this is an unstable rails 4.0.0 beta'

gem 'rails', '3.2.8'

Then run the bundle install然后运行捆绑安装

then do然后做

user@sandip:~/life/samplelogin$ rails c
Loading development environment (Rails 3.2.8)
1.9.3p362 :001 >

Before you start again, take a look at RBENV as an alternative to RVM.在重新开始之前,先看看 RBENV 作为 RVM 的替代品。 Its a lot cleaner and easier to use.它更清洁,更易于使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM