Ruby 2.5.0 was released last Christmas and it’s available through the usual places —
Docker makes it easy to run containers. It’s used in production, testing, and development. This tutorial focuses on development. I particularly like using Docker when a new version of Ruby is released to quickly try the new features. I can also check if my app’s gems will install correctly or if I need to upgrade them.
By using Docker, I can remove the image when I’m done. Not everyone can move to the latest Ruby version right away. With this method, I can try Ruby 2.5.0 without installing it permanently.
First, you need Docker. I use Docker for Mac. I also previously used Docker Machine. Docker is also available on Windows and Linux.
The ruby
docker run -it --rm ruby:2.5
If this is the first time you run the command, Docker will pull the image remotely. When it’s done, it will start the default program. In this caseirb
Unable to find image 'ruby:2.5' locally
2.5: Pulling from library/ruby
723254a2c089: Pull complete
abe15a44e12f: Pull complete
409a28e3cc3d: Pull complete
503166935590: Pull complete
0f46f97746e4: Pull complete
9d641d922d2f: Pull complete
891f591c9621: Pull complete
825fab4554b7: Pull complete
Digest: sha256:090577ac73868da6c74a2c5d716e67189e8f6c597b1d4bfbe61e8a68c829c02e
Status: Downloaded newer image for ruby:2.5
irb(main):001:0> RUBY_VERSION
=> '2.5.0'
You can now try the new features included in Ruby 2.5.0. I wrote about some of the highlights here.
For example, yield_self
is a new method.
irb(main):002:0> 3.yield_self{ |x| x*x }
=> 9
If you want to check how your code behaved in an older Ruby version, you can also use Docker for that. Instead of pulling the ruby:2.5
ruby:2.4
$ docker run -it --rm ruby:2.4
irb(main):001:0> RUBY_VERSION
=> '2.4.3'
irb(main):002:0> 3.yield_self{ |x| x*x }
NoMethodError: undefined method `yield_self' for 3:Integer
from (irb):2
from /usr/local/bin/irb:11:in `<main>'
yield_self
NoMethodError: undefined method
Another thing I try with new Ruby versions is
docker run -it --rm -v /Users/crigor/projects/todo:/todo ruby:2.5 bash
This command -v
/Users/crigor/projects/todo
/todo
Inside the bundle install
root@7c0b216b97c3:/# cd todo
root@7c0b216b97c3:/todo# bundle install
Fetching gem metadata from https://rubygems.org/..............
.
.
.
An error occurred while installing puma (2.10.2), and Bundler cannot continue.
Make sure that `gem install puma -v '2.10.2'` succeeds before bundling.
We can see that puma 2.10.2 failed to install on Ruby 2.5.0. Looking at the available puma versions, we can see that 2.10.2 is an old version. I tried updating to the latest version and it installed successfully.
root@7c0b216b97c3:/todo# bundle update puma
While puma 2.10.2 is old, note that it can still be installed without issues on Ruby 2.4.3. It is problems like this that can easily be checked using Docker. Not everyone can update to the latest Ruby version, especially in production. You usually want to give it time for some problems to surface before migrating to a new version. But you should start checking how much work needs to be done so you have an idea when the time comes.
If you have non-critical applications, you should consider using the Ruby 2.5.0 sooner rather than later. The community will thank you for that.
Are you ready to Deploy??
Start a 500 Hours Free Trial
{{cta(‘5019e5e3-8348-4b05-b8bf-ede6bb67025e’)}}
Deploy | Run | Scale