如何升级Rails?

Mic*_*umo 15 ruby ruby-on-rails

我是Ruby Rails的新手,以及所有这个命令行melarky.所以请耐心等待.

我已经按照各种教程安装了RubyGems,Homebrew,RVM,Rails等.

我想现在我已经完成了这一切,但是当我输入时:

rails --version
Run Code Online (Sandbox Code Playgroud)

我明白了,3.2.12.我注意到Rails 4已经出局了.如何升级到此版本?

如果我做:

gem install rails
Run Code Online (Sandbox Code Playgroud)

甚至做:

gem update rails
Run Code Online (Sandbox Code Playgroud)

我仍然得到3.2.12.

有任何想法吗?

UPDATE

在这里尝试一些选项时,我收到此消息...

Michaels-MacBook-Pro:~ ParanoidAndroid$ gem install rails --version=4.0
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby
    --with-atomic_reference-dir
    --without-atomic_reference-dir
    --with-atomic_reference-include
    --without-atomic_reference-include=${atomic_reference-dir}/include
    --with-atomic_reference-lib
    --without-atomic_reference-lib=${atomic_reference-dir}/lib
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:712:in `try_run'
    from extconf.rb:26:in `<main>'


Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p392/gems/atomic-1.1.14 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p392/gems/atomic-1.1.14/ext/gem_make.out
Run Code Online (Sandbox Code Playgroud)

似乎发生了错误.还有什么想法?

再次感谢大家!

thi*_*ign 15

如果您已经有一个Rails项目,您应该:

  • 在Gemfile中指定所需的版本(例如gem 'rails', '~> 5.2.0.rc1')
  • 跑步bundle install(bundle update可能需要)
  • 运行rails app:update(rake rails:update4.2及更早版本)
  • 按照屏幕上的说明操作
  • 根据您的版本,请按照官方指南了解其他步骤


Pur*_*gon 11

如果您正在使用RVM,那么您应首先创建一个单独的gemset,如:

rvm gemset create whateverName
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我将安装rails 4

rvm install 2.0.0

rvm list  

rvm 2.0.0 
Run Code Online (Sandbox Code Playgroud)

^^^^(您可能需要复制并粘贴版本号,因为它在rvm列表中显示)

rvm gemset create rails4

rvm gemset use rails4
Run Code Online (Sandbox Code Playgroud)

将以下内容添加到现有应用程序的gemfile中

gem 'rails', '4.0.0'
Run Code Online (Sandbox Code Playgroud)

然后运行

bundle update rails
Run Code Online (Sandbox Code Playgroud)

或者按照以下方式安装gem

gem install rails --version=4.0
Run Code Online (Sandbox Code Playgroud)

UPDATE

如果您没有安装Xcode 4.5 CLI工具,那么您将需要

首选项>下载>组件

DMG

https://developer.apple.com/downloads

然后你可能还需要使用自制软件来更新gcc

brew安装apple-gcc42

以下链接包含您需要的所有信息:

http://robots.thoughtbot.com/the-hitchhikers-guide-to-riding-a-mountain-lion


jan*_*oeh 5

gem update rails对你没有任何帮助,因为bundler确保只Gemfile加载和使用你指定的宝石.

因此,为了升级到Rails 4,您需要更改Gemfile中的Rails版本号并运行bundle update rails.

此Railscast将指导您完成将现有应用程序从Rails 3.2手动更新到Rails 4的所有步骤:

http://railscasts.com/episodes/415-upgrading-to-rails-4