Posted by Hiroshi SHIBATA on 8 Nov 2018

We released the official snap package of the Ruby language.

https://snapcraft.io/ruby

Snap is a package system developed by Canonical. It allows you to distribute a software with its dependencies for many different Linux systems. This solves the problem that a user cannot install the latest Ruby release from the default repository of their system like in rpm or apt .

On Ubuntu 16.04 or later, you can install the Ruby snap with the following command:

sudo snap install ruby --classic

(If you use other Linux distributions, please refer to https://docs.snapcraft.io/installing-snapd/6735.)

Our snap uses the “channel” feature to release multiple Ruby series concurrently. For example, without specifying a channel, currently Ruby 2.5.3 will be installed. But if you want to use Ruby 2.4, specify the 2.4 channel as follows:

sudo snap install ruby --classic --channel=2.4/stable

You can also use multiple channels. The following commands switch to Ruby 2.3:

sudo snap switch ruby --channel=2.3/stable sudo snap refresh

Our snap sets the GEM_HOME and GEM_PATH environment variables to $HOME/.gem . So if you want to execute commands installed by gems, such as rails and rspec , without using bundle exec , you have to add the following line to your shell rc files (like .bashrc ):

eval `ruby.env`

Since $HOME/.gem is shared by multiple versions, if you switch versions and use them, you will need to recompile C extensions using the gem pristine --extensions command.

The initial version of the official Ruby snap has been released during the Snapcraft summit held at the Canonical office in London on Nov 6-8th, 2018. Any feedback is welcome at https://github.com/ruby/snap.ruby.

Enjoy!