Ruby-on-rails 如何升级 Rails?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20703233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:09:06  来源:igfitidea点击:

How do I upgrade Rails?

ruby-on-railsruby

提问by Michael Giovanni Pumo

I am new to Ruby andRails, as well as all this command line melarky. So please bear with me.

我是 RubyRails 的新手,以及所有这些命令行 melarky。所以请耐心等待。

I have installed, RubyGems, Homebrew, RVM, Rails etc, by following various tutorials.

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

I think I have all of this going now, but when I type:

我想我现在已经完成了所有这些,但是当我输入:

rails --version

I get, 3.2.12. I notice that Rails 4 is out. How do I upgrade to this version?

我明白了,3.2.12。我注意到 Rails 4 已经发布了。我如何升级到这个版本?

If I do:

如果我做:

gem install rails

Even doing:

甚至做:

gem update rails

I still get 3.2.12.

我仍然得到 3.2.12。

Any ideas?

有任何想法吗?

UPDATE

更新

When trying a few options here, I get this message returned...

在这里尝试几个选项时,我收到了这条消息......

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

Seems there's an error happening. Any further ideas?

似乎发生了错误。任何进一步的想法?

Thanks again everyone!

再次感谢大家!

采纳答案by Purple Hexagon

If you are using RVM then you should create a seperate gemset first like:

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

rvm gemset create whateverName

in this example I will install rails 4

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

rvm install 2.0.0

rvm list  

rvm 2.0.0 

^^^^(you may need to copy and paste the version number exactly here as it was displayed in rvm list)

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

rvm gemset create rails4

rvm gemset use rails4

add the following to your gemfile for existing apps

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

gem 'rails', '4.0.0'

then run

然后运行

bundle update rails

or do following to just install the gem

或执行以下操作以安装 gem

gem install rails --version=4.0

UPDATE

更新

If you havne't installed Xcode 4.5 CLI tools then you will need to

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

Preferences > Downloads > Components

首选项 > 下载 > 组件

DMG

DMG

https://developer.apple.com/downloads

https://developer.apple.com/downloads

you may then also need to use homebrew to update gcc

您可能还需要使用自制软件来更新 gcc

brew install apple-gcc42

酿造安装苹果-gcc42

the following link has all the information you will need:

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

https://thoughtbot.com/blog/the-hitchhikers-guide-to-riding-a-mountain-lion

https://thoughtbot.com/blog/the-hitchhikers-guide-to-riding-a-mountain-lion

回答by thisismydesign

If you already have a Rails project you should:

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

  • Specify the desired version in your Gemfile (e.g. gem 'rails', '~> 5.2.0.rc1')
  • Run bundle install(bundle updatemay be needed)
  • Run rails app:update(rake rails:updatefor 4.2 and earlier)
  • Follow instructions on screen
  • Follow the official guidefor additional steps depending on your version
  • 在您的 Gemfile 中指定所需的版本(例如gem 'rails', '~> 5.2.0.rc1'
  • 运行bundle installbundle update可能需要)
  • 运行rails app:updaterake rails:update适用于 4.2 及更早版本)
  • 按照屏幕上的说明进行操作
  • 根据您的版本,按照官方指南获取其他步骤

回答by janfoeh

gem update railsdoes nothing for you, because bundlermakes sure that only the gems specified in your Gemfileare loaded and used.

gem update rails对你没有任何作用,因为bundler确保只有你指定的 gemGemfile被加载和使用。

So in order to upgrade to Rails 4, you need to change the Rails version number in your Gemfile and run bundle update rails.

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

This Railscast guides you through all the steps of manually updating an existing application from Rails 3.2 to Rails 4:

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

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

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

回答by Pravin Mishra

You can install either with specific version OR putting gem version in itself Gemfile.

您可以使用特定版本安装或将 gem 版本放在 Gemfile 中。

gem install rails -v 4.0.0

回答by juco

You can get a list of all gem versions with

您可以获得所有 gem 版本的列表

gem list rails --remote --all

To install specify version 4.0.1 for example you can use

例如,要安装指定版本 4.0.1,您可以使用

gem install rails -v 4.0.1

Or you could just specify the version in your Gemfile

或者你可以在你的 Gemfile 中指定版本

回答by k clark

Best to use gem list --remote --all. Unless your looking for that particular version as long as the gemset for that project has been established

最好使用 gem list --remote --all。除非您正在寻找该特定版本,只要该项目的 gemset 已经建立