Ruby Kernel for Jupyter Notebook

Jupyter notebooks are nice way to keep your code, diagrams, documentation together, mostly in a single file, which is also executable i.e. can run/interpret your code in it, and also have the result saved as it is. Here’s blogpost for installing Jupyter Notebook – today I’ll share how to use Ruby kernel with Jupyter Notebook i.e. executing Ruby code inside the notebooks.
To create notebooks that can execute Ruby code we need to integrate Ruby kernel, the 3 simple steps are:
  • Install Jupyter
  • Install Ruby
  • Install iruby

The procedure is pretty simple, but the issue here is iruby requires
  • Jupyter >= 3.0.0
  • Ruby >= 2.1.0
  • CZMQ >= 4.0.0 – the C binding for ZeroMQ.
For example – CentOS 7.1 installs Ruby 2.0.0, so we need to manually install latest Ruby, using rbenv.

Step 1: Install Jupyter Notebook

Install iPython

pip install ipython
For Python < 3.3 install iPython 5
pip install ipython==5.0.0

Install jupyter

pip install jupyter
There’s a separate post about installing and using Jupyter Notebook.

Step 2: Install Ruby >= 2.1.0

The OS level dependencies and Ruby

sudo yum install -y git-core ruby-devel ruby zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make

Verify

ruby-version

NOTE: Chances are the installed version of Ruby will be less than the required 2.1.0, for this you can install manually using rbenv – Install latest Ruby version using rbenv.

Step 3: Install iruby

The Ruby kernel requires ZeroMQ, hence it’s C and Ruby bindings
sudo yum install zeromq-devel zeromq czmq
gem install cztop rbczmq ffi_rzmq
gem install iruby
It’ll install 5 Ruby gems/packages – bond, multi_json, mimemagic, data_uri, iruby.
Output
Successfully installed iruby-0.3
Parsing documentation for bond-0.5.1
Installing ri documentation for bond-0.5.1
Parsing documentation for multi_json-1.12.1
Installing ri documentation for multi_json-1.12.1
Parsing documentation for mimemagic-0.3.2
Installing ri documentation for mimemagic-0.3.2
Parsing documentation for data_uri-0.1.0
Installing ri documentation for data_uri-0.1.0
Parsing documentation for iruby-0.3
Installing ri documentation for iruby-0.3
Done installing documentation for bond, multi_json, mimemagic, data_uri, iruby after 2 seconds
5 gems installed
$ iruby register --force

Start the jupyter

In your working directory
$ jupyter notebook
Now you can create Ruby notebooks, in the new drop-down on the right side you can see the Ruby 2.4.1 listed.
iruby

Leave a Reply

Your email address will not be published. Required fields are marked *