如何从 ruby​​ 2.2.3 升级到 ruby​​ 2.3.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37201151/
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-06 06:49:30  来源:igfitidea点击:

How to upgrade from ruby 2.2.3 to ruby 2.3.0

rubyrbenv

提问by Jeramae Bohol

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 rbenvusing this guide: gorails.com/setup/ubuntu/16.04

我使用本指南使用rbenvgorails.com/setup/ubuntu/16.04

How do I upgrade my Ruby version? And when I upgrade, does it affect anything that I need to be aware of?

如何升级我的 Ruby 版本?当我升级时,它会影响我需要注意的任何事情吗?

回答by Michael Gaskill

This answer had been written to address the originalquestion, which did not specify rbenvas a preferred approach. 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.

编写此答案是为了解决原始问题,该问题并未指定rbenv为首选方法。尽管在编写此答案后问题发生了变化,但仍保留了答案以帮助可能使用 RVM 升级/管理其 Ruby 安装的用户。

See the rbenv answerfor details on using rbenvfor the same purpose.

有关用于相同目的的详细信息,请参阅rbenv 答案rbenv



Use RVMor another Ruby version manager. This is far superior to installing a new system Ruby in most cases.

使用RVM或其他 Ruby 版本管理器。在大多数情况下,这远优于安装新系统 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?
  • 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?
  • are there any other users using the existing Ruby that need to be aware of (and prepare for) the change?
  • 该 Ruby 版本还有哪些其他依赖项?
  • 升级后所有的宝石都可用吗?
  • 哪些应用程序正在使用现有的 Ruby 版本,升级后哪些可能/将会中断?
  • 是否有其他使用现有 Ruby 的用户需要了解(并准备)更改?

With a Ruby version manager, you eliminate most of these concerns. You can run multiple Ruby versions on the same machine, which gives you the ability to test backward and forward compatibility. It also lets you experiment with the newer Ruby versions to make sure that they're fully stable for use.

使用 Ruby 版本管理器,您可以消除大部分这些顾虑。您可以在同一台机器上运行多个 Ruby 版本,这使您能够测试向后和向前兼容性。它还可以让您试验较新的 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 usecommand:

使用以下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 documentationfor more features. You'll be surprised at how useful RVM actually is. There's a whole lot more to it than just what's shown here.

查看RVM 文档了解更多功能。您会惊讶于 RVM 的实际用途。除了这里显示的内容之外,还有更多内容。

回答by Michael Gaskill

To upgrade your Ruby version using rbenv, you can use these steps. Some will only be necessary based on your environment. Pluginsare an important aspect of this, if you have any installed.

要使用rbenv升级您的 Ruby 版本,您可以使用以下步骤。有些仅根据您的环境是必要的。 如果您安装了插件,插件是其中的一个重要方面。

Update rbenbv

更新 rbenbv

First, you'll want to make sure that your rbenvversion is updated. If you have the update plugininstalled, you can update rbenvand all installed plugins using a single command:

首先,您需要确保您的rbenv版本已更新。如果安装了更新插件,则可以rbenv使用单个命令更新和所有已安装的插件:

rbenv update

Using the updateplugin is highly recommended. However, if you are not using the updateplugin, you can manually update rbenvin this way:

update强烈建议使用该插件。但是,如果您没有使用该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. Make sure to follow the update instructions for each plugin.

如果您手动更新了rbenv,您还需要手动更新插件。确保遵循每个插件的更新说明。

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. This may improve the experience installing a new Ruby version in the next step.

此时需要更新的一个非常重要的插件(如果已安装)是ruby-build 插件,它在rbenv. 这可能会改善下一步安装新 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 版本

rbenvwill allow you to manage and use multiple Ruby versions on a single machine. This is a huge benefit. However, if you no longer want the older Ruby version installed, you can remove it like this:

rbenv将允许您在一台机器上管理和使用多个 Ruby 版本。这是一个巨大的好处。但是,如果您不再需要安装较旧的 Ruby 版本,您可以像这样删除它:

rbenv uninstall 2.2.3

Note that you can always re-install the Ruby version after uninstalling it, and use rbenvto manage the versions separately. This is good practice when working with multiple projects.

请注意,您始终可以在卸载后重新安装 Ruby 版本,并用于rbenv单独管理版本。在处理多个项目时,这是一种很好的做法。