19

My current Ruby version is 2.2.3 and I want to upgrade it to 2.3.0.

I use rbenv using this guide: gorails.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?

Wayne Conrad
  • 103,207
  • 26
  • 155
  • 191
Jeramae Bohol
  • 191
  • 1
  • 1
  • 6

2 Answers2

20

This answer had been written to address the original question, which did not specify rbenv as 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.

See the rbenv answer for details on using rbenv for the same purpose.


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

If you're upgrading your system Ruby, you have a number of things to keep in mind:

  • 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?

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.

You can install RVM using this method from any bash shell:

\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 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:

rvm list

You can also check to see which versions of Ruby that you can install on RVM by using this command:

rvm list known

Switch to a specific installed Ruby version by using the use command:

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

Community
  • 1
  • 1
Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43
  • Also, if you are under RVM already, `rvm get stable; rvm upgrade 2.3.0 2.3.1` is pretty neat. – Amadan May 13 '16 at 05:40
  • @Michael The OP wants to upgrade to 2.3.0. – sawa May 13 '16 at 05:44
  • Oops, `rvm upgrade 2.2.3 2.3.1` – Amadan May 13 '16 at 05:45
  • 1
    @sawa I originally had 2.3.0 in the example, and changed it when I saw your comment about 2.3.0 being buggy and undesirable, and then tadman's comment about 2.3.1 availability. I'll adjust to match the question, rather than the dialogue following it. – Michael Gaskill May 13 '16 at 05:47
  • @JeramaeBohol I wrote this answer before that information was available. I can write another that addresses how to do what you need with rbenv. – Michael Gaskill May 13 '16 at 07:17
  • Yeah my bad. I forgot to write it. – Jeramae Bohol May 13 '16 at 07:21
  • The question was regarding rbenv rather than rvm. If rvm is superior or not is definitely subjective – Nuno Costa Feb 15 '17 at 16:24
  • @NunoCostaThe comment about superiority was related to using a version manager (e.g. RVM) instead of installing a new **system Ruby**, not about RVM being superior to rbenv. The original question did not specify rbenv, and this answer was written before any details about the OP using rbenv were provided. Once it became known that the OP was using rbenv, I added those details to the question. – Michael Gaskill Feb 15 '17 at 17:04
  • In general you want to use latest security patch, so if 2.3.5 is the latest minor version of 2.3.x then you should use that over say 2.3.0 or 2.3.1, because the ruby API does not change, but bugs and security vulnerabilities are fixed. – shushugah Jan 28 '19 at 14:16
11

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

Update rbenbv

First, you'll want to make sure that your rbenv version is updated. If you have the update plugin installed, you can update rbenv and all installed plugins using a single command:

rbenv update

Using the update plugin is highly recommended. However, if you are not using the update plugin, you can manually update rbenv in this way:

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.

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.

Install Ruby version

After you have updated rbenv, you can install the new Ruby version:

rbenv install -v 2.3.0

Remove Ruby version

rbenv will 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 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. This is good practice when working with multiple projects.

Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43
  • 2
    If you are using the `ruby-build` plugin for rbenv you will want to update that before installing Ruby, to be able to get the latest version. `cd ~/.rbenv/plugins/ruby-build; git pull` – Sunil D. Aug 05 '16 at 17:34
  • @SunilD. Great suggestion, thanks! Based on your comment, I went ahead and added more information about plugins, particularly the `ruby-build` that you mentioned, as well as the `update` plugin. Good stuff to add, and thanks for the tip! – Michael Gaskill Aug 05 '16 at 21:57