简体   繁体   English

如何从ruby 2.2.3升级到ruby 2.3.0

[英]How to upgrade from ruby 2.2.3 to ruby 2.3.0

My current Ruby version is 2.2.3 and I want to upgrade it to 2.3.0. 我目前的Ruby版本是2.2.3,我想将其升级到2.3.0。

I use rbenv using this guide: gorails.com/setup/ubuntu/16.04 我使用本指南使用rbenvgorails.com/setup/ubuntu/16.04

How do I upgrade my Ruby version? 如何升级我的Ruby版本? And when I upgrade, does it affect anything that I need to be aware of? 当我升级时,它是否会影响我需要注意的任何事情?

This answer had been written to address the original question, which did not specify rbenv as a preferred approach. 这个答案是为解决原始问题而编写的,该问题没有将rbenv指定为首选方法。 Although the question changed after this answer was written, the answer has been retained to help users that may be using RVM to upgrade/manage their Ruby installations. 尽管在编写完这个答案后问题已经改变,但仍然保留了答案,以帮助可能正在使用RVM升级/管理其Ruby安装的用户。

See the rbenv answer for details on using rbenv for the same purpose. rbenv回答关于使用细节rbenv为了同样的目的。


Use RVM or another Ruby version manager. 使用RVM或其他Ruby版本管理器。 This is far superior to installing a new system Ruby in most cases. 在大多数情况下,这远远优于安装新系统Ruby。

If you're upgrading your system Ruby, you have a number of things to keep in mind: 如果您正在升级系统Ruby,那么您需要记住以下几点:

  • what other dependencies are there on that Ruby version? Ruby版本还有哪些其他依赖项?
  • are all of the gems going to be available after upgrade? 升级后所有的宝石都可用吗?
  • which applications are using the existing Ruby version and what can/will break after upgrade? 哪些应用程序使用现有的Ruby版本以及升级后可以/将要破坏的内容?
  • are there any other users using the existing Ruby that need to be aware of (and prepare for) the change? 有没有其他用户使用现有的Ruby需要了解(并准备)更改?

With a Ruby version manager, you eliminate most of these concerns. 使用Ruby版本管理器,您可以消除大多数这些问题。 You can run multiple Ruby versions on the same machine, which gives you the ability to test backward and forward compatibility. 您可以在同一台机器上运行多个Ruby版本,这使您能够测试向后和向前兼容性。 It also lets you experiment with the newer Ruby versions to make sure that they're fully stable for use. 它还允许您体验较新的Ruby版本,以确保它们完全稳定可供使用。

You can install RVM using this method from any bash shell: 您可以从任何bash shell使用此方法安装RVM:

\curl -sSL https://get.rvm.io | bash -s stable

or update it to the most recent stable version by using: 或使用以下方法将其更新为最新的稳定版本:

rvm get stable

Once RVM is installed (or updated), you can install any Ruby version you choose, by doing the following: 安装(或更新)RVM后,您可以通过执行以下操作来安装您选择的任何Ruby版本:

rvm install 2.3.0

or upgrade from one version to another: 或从一个版本升级到另一个版本:

rvm upgrade 2.2.3 2.3.0

You can see which Ruby versions are installed by using this: 您可以使用以下命令查看安装了哪些Ruby版本:

rvm list

You can also check to see which versions of Ruby that you can install on RVM by using this command: 您还可以使用以下命令检查可以在RVM上安装哪些版本的Ruby:

rvm list known

Switch to a specific installed Ruby version by using the use command: 使用use命令切换到特定的已安装Ruby版本:

rvm use 2.3.0

and then switch back to an older version when you need to: 然后在需要时切换回旧版本:

rvm use 2.2.3

Check out the RVM documentation for more features. 查看RVM文档以获取更多功能。 You'll be surprised at how useful RVM actually is. RVM实际上有多么有用,你会感到惊讶。 There's a whole lot more to it than just what's shown here. 除了这里展示的内容之外,还有更多内容。

To upgrade your Ruby version using rbenv , you can use these steps. 要使用rbenv升级Ruby版本,可以使用这些步骤。 Some will only be necessary based on your environment. 有些仅根据您的环境而有必要。 Plugins are an important aspect of this, if you have any installed. 如果你有任何安装, 插件是一个重要的方面。

Update rbenbv 更新rbenbv

First, you'll want to make sure that your rbenv version is updated. 首先,您需要确保更新您的rbenv版本。 If you have the update plugin installed, you can update rbenv and all installed plugins using a single command: 如果安装了更新插件 ,则可以使用单个命令更新rbenv和所有已安装的插件:

rbenv update

Using the update plugin is highly recommended. 强烈建议使用update插件。 However, if you are not using the update plugin, you can manually update rbenv in this way: 但是,如果您不使用update插件,则可以通过以下方式手动更新rbenv

cd ~/.rbenv
git pull

Update plugins 更新插件

If you have manually updated rbenv , you'll also need to update the plugins manually, as well. 如果您手动更新了rbenv ,那么您还需要手动更新插件。 Make sure to follow the update instructions for each plugin. 请务必遵循每个插件的更新说明。

One plugin that's very important to update at this point (if you have it installed) is the ruby-build plugin , which provides build support for Ruby under rbenv . 一个在这一点上更新非常重要的插件(如果已安装它)是ruby-build插件 ,它在rbenv下为Ruby提供构建支持。 This may improve the experience installing a new Ruby version in the next step. 这可能会改善下一步安装新Ruby版本的体验。

Install Ruby version 安装Ruby版本

After you have updated rbenv , you can install the new Ruby version: 更新rbenv ,您可以安装新的Ruby版本:

rbenv install -v 2.3.0

Remove Ruby version 删除Ruby版本

rbenv will allow you to manage and use multiple Ruby versions on a single machine. rbenv允许您在一台机器上管理和使用多个Ruby版本。 This is a huge benefit. 这是一个巨大的好处。 However, if you no longer want the older Ruby version installed, you can remove it like this: 但是,如果您不再需要安装旧的Ruby版本,则可以将其删除,如下所示:

rbenv uninstall 2.2.3

Note that you can always re-install the Ruby version after uninstalling it, and use rbenv to manage the versions separately. 请注意,卸载后可以随时重新安装Ruby版本,并使用rbenv单独管理版本。 This is good practice when working with multiple projects. 在处理多个项目时,这是一种很好的做法。

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

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