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

How can I start my Ruby environment from scratch?

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

我目前已经通过RVM安装了Ruby1.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'
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
'

我能做些什么来解决这个问题?我想回到Mac附带的Ruby版本。

(编辑:我在雪豹10.6.8上)

编辑2:

不过,我现在已经让rvm运行Ruby1.9.2和Rails3.0.9,尝试使用rails server启动服务器时返回以下内容:

AppMachineMobile:hello Moshe$ rails server

=> Booting WEBrick

=> Rails 3.0.9 application starting in development on http://0.0.0.0:3000

=> Call with -d to detach

=> Ctrl-C to shutdown server

Exiting

/Users/Moshe/Development/Ruby/hello/config/initializers/new_rails_defaults.rb:14: undefined method `generate_best_match=' for ActionDispatch::Routing:Module (NoMethodError)

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

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

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

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

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

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

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

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

from /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

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

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

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

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


我会努力从头开始。检查已安装的RVM:

1
$rvm list

你应该得到这样的信息:

1
2
3
4
5
6
7
8
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卸载:

1
2
$rvm uninstall 1.8.7
$rvm uninstall 1.9.2

安装Ruby 1.8.7:

1
$ rvm install 1.8.7

安装最新的Ruby 1.9.2:

1
$ rvm install 1.9.2

设置默认值(或1.8.7,如果您需要):

1
$ rvm use 1.9.2 --default

安装PostgreSQL和sqlite gems(假设雪豹):

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

安装导轨3(包括打捆机):

1
$ gem install rails

如果您在Rails 2X项目中:

1
$rvm use 1.8.7

如果您在Rails 3项目中:

1
$rvm use 1.9.2

当您在每个RVM中时,如果您使用bundler,则通过"bundle install"加载与项目相关联的gems;如果您将所有内容都转储到环境中,则通过"rake gems:install"加载与项目相关联的gems。rb


1
rm -rf .rvm .rvmrc

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

除非您已经安装了一个系统范围的Ruby,除了通过RVM安装一个以外,您再也没有"ruby"命令了,直到您重新安装了RVM。

所以:

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

重新安装RVM。现在一切都应该恢复到默认安装。


在您再次开始之前,请看一下RBENV作为RVM的替代方案。它更干净,更容易使用。


这可能会有所帮助:

http://blog.parsalabs.com/blog/2013/08/27/setting-up-a-ruby-on-rails-4-development-environment-on-a-clean-mac-os-x-installation/

RBENV是一个很棒的工具来管理你的红宝石。


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

1
2
3
4
5
6
7
8
9
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。

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

gem 'rails', '3.2.8'

然后运行bundle安装

然后做

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