Use Ruby with Google Colab

I tried running Ruby with Google Colab did not work as it is as of July 2020, so try it by trial and error with reference to Julia's example. I will introduce it because it went well.

Easy execution

1. File download

Right-click this file and select "Save Link" on your computer. Download to.

2. Notebook upload

Open https://colab.research.google.com/ and "upload" the file downloaded from the above ("File"-> "Upload notebook" if you opened Google Collaboratory for the first time).

3. Install Ruby and required software

A notebook with two pre-coded cells will open. Click the top cell and just press Shift + Enter (or the button with the right triangle) to execute. It will take some time. At the bottom, runtime" ruby "is not recognized. I get the message Connect to the default" python3 "but ignore it.

4. Install additional gems

Go to the second cell, make an edit that leaves only the row for the gem you want to install, then press Shift + Enter (or the button with the right triangle) to do it.

5. Switch runtime to ruby

Press Runtime> Change Runtime Type. This will bring up the Notebook Settings window with "ruby 2.5.1" selected as the "Runtime Type". Make sure "ruby 2.5.1" is selected as the "Runtime Type" and press "Save". (If it is not selected, select "ruby 2.5.1" from the list and save it.)

6. Execute Ruby code

Now you have an environment to execute Ruby code. For example, if you type RUBY_VERSION and press Shift + Enter, you should see"2.5.1".


Manual operation

This is how to do the above manually. I will describe it in case the environment on the Google side changes.

1. Create a new notebook with Google Colaboratory

Open https://colab.research.google.com/ and press "New Notebook" ("File"-> "New Notebook" if you opened Google Collaboratory for the first time) to create a new notebook. Create.

2. Download as is in ipynb format

Download a blank notebook with nothing entered by selecting "File"-> "Download ipynb".

3. Edit the downloaded file on your computer

This section is done with a text editor on your computer. Look for the following part of the file that starts with " kernelspec ".

    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }

Rewrite the above " python 3 " and " Python 3 " for Ruby as follows.

    "kernelspec": {
      "name": "ruby",
      "display_name": "ruby 2.5.1"
    }

After rewriting, save it.

4. Upload the rewritten notebook

Upload the file you just rewritten from "File"-> "Upload Notebook" in Google Colaboratory on your web browser.

5. Install Ruby and required software

Copy and paste the following into the cell (where you enter) in Google Collaboratory.

!apt install libtool libffi-dev ruby-full make
!apt install libzmq3-dev libczmq-dev
!gem install ffi-rzmq
!gem install specific_install
!gem specific_install https://github.com/SciRuby/iruby
!iruby register

Then press Shift + Enter to run. It will take some time. At the bottom, runtime" ruby "is not recognized. I get the message Connect to the default" python3 "but ignore it.

6. Install additional gems

Install additional gems as needed. Copy and paste the following, then leave only the line for the gem you want to install. Then press Shift + Enter to run.

!gem install awesome_print
!gem install pry
!gem specific_install https://github.com/SciRuby/daru
!gem specific_install https://github.com/SciRuby/daru-view
!gem install numo-narray
!gem install rumale
!gem install bio

7. Switch runtime to ruby

Perform the same operation as "5. Switch runtime to ruby" in Easy Execution.

8. Execute Ruby code

Now you have an environment to execute Ruby code.

Reference material

  1. I tried running Ruby on Google Colab --This article would not have been possible without this article. The apt installation package and iruby installation method have been partially changed based on this article.

  2. Use Julia with Google Colab: Use the original notebook --How to rewrite json of ipynb and install the language after uploading and switch the runtime I referred to.

Recommended Posts

Use Ruby with Google Colab
Solve Google problems with Ruby
Let's use Amazon Textract with Ruby
Use Java 11 with Google Cloud Functions
Procedure for operating google spreadsheet with API (ruby)
Use ProGuard with Gradle
Install Ruby 3.0.0 with asdf
Use Puphpeteer with Docker
Use XVim2 with Xcode 12.0.1
Use CentOS with LXD
Use ngrok with Docker
Use webmock with Rspec
Use WebJars with Gradle
11th, Classification with Ruby
Use jlink with gradle
Evolve Eevee with Ruby
Use Coveralls with GitHub Actions in a Ruby repository
Use Lambda Layers with Java
Use GDAL with Python with Docker
Use Thymeleaf with Azure Functions
Ruby version switching with rbenv
I tried DI with Ruby
GraphQL Client starting with Ruby
Use pfx certificate with Okhttp3
How to use Ruby return
Use Bulk API with RestHighLevelClient
Leap year judgment with Ruby
Use C program from Ruby
Use Face API from Ruby
Format Ruby with VS Code
Integer check method with ruby
Use ruby variables in javascript.
Use SDKMAN! With Git Bash
Use multiple databases with Rails 6.0
Rbenv command to use Ruby
Ruby: How to use cookies
Ruby Learning # 8 Working With String
[Ruby] problem with if statement
Just use OpenVINO's face detection demo in (Google Colab | Docker)
Studying with CodeWar (ruby) ⑤ proc
Use SpatiaLite with Java / JDBC
Use log4j2 with YAML + Gradle
[Ruby] REPL-driven development with pry
Getting Started with Ruby Modules
[Docker] Use whenever with Docker + Rails
[ruby] Method call with argument
[Linux: Ruby] Use the driver with selenium without specifying the browser driver path
Use java with MSYS and Cygwin
Ruby Scraping-Move Selenium Headless with VPS.
Use constructor with arguments in cucumber-picocontainer
Learning Ruby with AtCoder 6 [Contest 168 Therefore]
Use Microsoft Graph with standard Java
Why use orchestration tools with Docker
Use bootstrap 4 with PlayFramework 2.6 (no CDN)
Use Git with SourceTree and Eclipse
Use Azure Bing SpellCheck with Java
Programming with ruby (on the way)
Studying with CodeWar (ruby) ④ case ~ when
Use DataDog APM with unsupported frameworks
[Ruby] How to use any? Method
[Google Cloud] Getting Started with Docker