如何从头开始创建Ruby环境?

时间:2011-07-06 18:45:27

标签: ruby-on-rails ruby runtime installation

我一直在尝试升级我的MacBook上的rails环境而且我搞砸了什么,但我不确定是什么。是否可以完全删除RVM,Ruby和Rails并从头开始?我对这一切都应该如何工作感到很困惑。

我目前通过RVM安装了Ruby 1.8.7和1.9.2。我把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'       来自/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'

我可以做些什么来解决这个问题?我想恢复我的Mac附带的ruby版本。

编辑:我在Snow Leopard 10.6.8上)

EDIT2:

我现在已经获得了运行ruby 1.9.2和rails 3.0.9的rvm但是,尝试使用rails server启动服务器会返回以下内容:

  

AppMachineMobile:你好Moshe $ rails服务器

     

=>启动WEBrick

     

=> Rails 3.0.9应用程序从http://0.0.0.0:3000

开始开发      

=>使用-d调用分离

     

=> Ctrl-C关闭服务器

     

退出

     

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

     

来自/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'

     

来自/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:596:in"new_constants_in'

     

来自/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:235:in"load'

     

来自/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:200:in` each'

     

来自/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/initializable.rb:25:in`instance_exec'

     

来自/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:50:in,run_initializers'

     

来自/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,run_initializers'

     

来自/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:77:in`send'

     

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

     

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

     

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

     

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

     

来自/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`initialize'

     

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

     

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

5 个答案:

答案 0 :(得分:3)

我会尝试从头开始。检查您安装的rvms:

$rvm list

你应该得到这样的东西:

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 ]

对每件作品进行rvm卸载:

$rvm uninstall 1.8.7
$rvm uninstall 1.9.2

安装Ruby 1.8.7:

$ rvm install 1.8.7

安装最新的Ruby 1.9.2:

$ rvm install 1.9.2

设置默认值(如果需要,则设置为1.8.7):

$ rvm use 1.9.2 --default

安装PostgreSQL和SQLite宝石(假设雪豹):

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

安装Rails 3(包括Bundler):

$ gem install rails

如果你在rails 2x项目中:

$rvm use 1.8.7

如果您参与rails 3项目:

$rvm use 1.9.2

当你在每个rvm中时,如果你正在使用bundler,则通过'bundle install'加载与项目关联的gem;如果你把所有东西都转移到你的环境中,则加载'rake gems:install'.rb

答案 1 :(得分:2)

rm -rf .rvm .rvmrc

然后删除项目目录中的.rvmrc文件,如果你想确保从头开始。

除非你安装了一个系统范围的ruby,除了通过rvm安装一个,你再也没有“ruby”命令,直到你再次重新安装rvm。

所以:

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

重新安装rvm。现在一切都应该回到默认安装。

答案 2 :(得分:0)

我没有删除任何.rvm和.rvmrc文件。但我的问题已经解决了。我不知道它是如何解决的。但是我告诉你的是我做了什么。首先我在我的Gemfile中使用了不稳定版本的rails gem。这就是问题发生的原因。

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>'

接下来我做了什么,我只是从本地文件夹中评论gem。

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

gem 'rails', '3.2.8'

然后运行bundle install

然后做

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

答案 3 :(得分:0)

答案 4 :(得分:0)

在重新开始之前,请先看看RBENV作为RVM的替代方案。它更清洁,更容易使用。