Setting Up a Ruby Development Environment

This tutorial shows how to prepare your local machine for Ruby development, including developing Ruby applications that run on Google Cloud Platform. Follow this tutorial to install Ruby and relevant tools.

Read Quickstart for Ruby and Google Cloud Platform to get an overview of Ruby itself and learn ways to run Ruby apps on Google Cloud Platform.

Objectives

  • Install Ruby
  • Install Bundler
  • Install an editor (optional)
  • Install the Google Cloud SDK
  • Install the Google Cloud Client Library for Ruby

Install Ruby

Ruby's installation instructions vary by operating system. Follow the guide for the operating system you're using on your local development machine. This tutorial applies to stable and non-EOL Ruby versions listed on Ruby-lang.

Mac OS X

Our recommended way of installing Ruby on Mac OS X is to use rbenv to manage your Ruby installations. rbenv manages multiple Ruby version installations on your machine and a rbenv plugin named ruby-build adds support to rbenv to install a specified version of Ruby.

While OS X includes a version of Ruby by default, it's best to perform a separate install of the latest versions of Ruby to stay up-to-date and avoid conflicts with the operating system's use of its default version.

  1. Install XCode.
  2. Install XCode's Command Line Tools by using the following command in a terminal:

    xcode-select --install
    
  3. Install homebrew by following the instructions on the homebrew homepage.

  4. Install rbenv by using homebrew the following instructions on the rbenv readme. Using the homebrew installation will include the ruby-build plugin.

Learn more about using rbenv and ruby-build to install different versions of Ruby.

Linux

Our recommended way of installing Ruby on a Linux distribution is to use rbenv to manage your Ruby installations. rbenv manages multiple Ruby version installations on your machine and a rbenv plugin named ruby-build adds support to rbenv to install a specified version of Ruby.

  1. Install rbenv on your Linux distribution using the rbenv readme.

  2. Install the ruby-build plugin for rbenv using the instructions on the ruby-build readme.

Learn more about using rbenv and ruby-build to install different versions of Ruby.

Windows

For Windows, we recommend one of the following:

Install Bundler

Bundler is a Ruby gem that manages project gem dependencies defined in a file name Gemfile. The Ruby samples in Google Cloud Platform documentation use Gemfiles to specify required gems and versions.

To install Bundler use the following command:

gem install bundler

To install gem dependencies defined in the Gemfile, use the following command:

bundle install

To run your Ruby project only using gems defined in your Gemfile use the following command:

bundle exec ruby app.rb

Learn more about creating a Gemfile by reading Bundler documentation.

Install an editor

Popular editors (in no particular order) used to develop Ruby applications include, but are not limited to:

These editors (sometimes with the help of plugins) give you everything from syntax highlighting, intelli-sense, and code completion to fully integrated debugging capabilities, maximizing your Ruby development efficacy.

Install the Google Cloud SDK

The Google Cloud SDK is a set of tools for Google Cloud Platform. It contains gcloud, gsutil, and bq, which you can use to access Google Compute Engine, Google Cloud Storage, Google BigQuery, and other products and services from the command line. You can run these tools interactively or in your automated scripts.

As an example, here is a simple command that will deploy a Ruby web application to Google App Engine flexible environment after deployment App Engine will attempt to start the application with bundle exec ruby app.rb -p 8080:

gcloud app deploy

Learn more on how to deploy a Ruby on Rails application to Google App Engine flexible environment.

Install the Google Cloud Client Library for Ruby

The Google Cloud Client Library for Ruby is the idiomatic way for Ruby developers to integrate with Google Cloud Platform services. You can install the package for an individual API such as Cloud Storage for example:

gem install google-cloud-storage

You can also use Bundler and add the gem to your Gemfile dependencies, for example:

bundle add google-cloud-storage

Authentication

To use this client library, you must first authenticate. Complete the steps at getting started with authentication.

Next Steps

Was this page helpful? Let us know how we did:

Send feedback about...