Ruby Development with VS Code

Terrence Ong
Aug 27, 2017 · 3 min read

In my post of Getting Started with Ruby I talked about the basic of Ruby programming. You can try to play around with ruby in the online browser IDE. But if you want to develop something serious with Ruby, then you will want to setup your local development environment.

From what I observed from the internet, RubyMine from JetBrains seems to be the most agreed best IDE for Ruby (with a price of $89.00). If you are just getting started with a new language, it’s very unlikely that you would invest the money. So let’s explore the alternative with Visual Studio Code, which work very well too.

Installing Visual Studio Code

Visual Studio Code is an open source code editor from Microsoft. It is completely FREE and very customizable. Installing VS Code is a breeze. Go to VS Code home page and download the installer for the OS you are using (Windows, OS X ,and Linux), follow the install wizard to complete the setup.

Installing Ruby

Check out the official Ruby installation guide by Ruby site. I will recommend using rbenv if you are OS X or Linux user. Windows user may install Ruby by downloading the Ruby installer for Windows. I’m a OS X user, Ruby is pre-installed in OS X. However, I would recommend ruby developer to use rbenv to manage your development environment as it will not mess with the version of system installed Ruby runtime.

Assume that you have had homebrew installed. Run this command in Terminal to install rbenv:

brew install rbenv

then, quit Terminal and re-open again for rbenv to take effect. You may run rbenv -v to verify if rbenv was installed successfully.

Then, we can install Ruby 2.4.1 (latest version as I wrote this) by running:

rbenv install 2.4.1

Setup Visual Studio Code for Ruby Development

Before we open up the VS Code, we need to install the debugger for Ruby with Gem by running:

gem install ruby-debug-ide -v 0.6.0

By, default visual studio doesn’t include the debug configuration for Ruby, we need to install an extension for Ruby debug config.

Open up your VS Code. Go to the extension tab and search for “Ruby”

Install the Ruby extension. Now you should be able to debug your Ruby code in VS Code. Let’s see how it works in action next.

All Set. Action Time!

Let create a project folder and open it with Visual Studio.

Here, I named my folder “GORUBY”.

Then create a file “main.rb” in the folder. This will be the entry file for our first Ruby program.

Paste the following code into the file:

your_name = "Terrence"puts "Hello #{your_name}"

Press F5 to start debug your code.

you will be prompted to select a debug environment. Select Ruby.

To see the result, you need to open up the Debug Console by pressing “Cmd + `”.

Now, try to put a breakpoint on Line 3,

So now you’re ready to create some awesome stuff with Ruby.

If you are just getting started with Ruby and want to learn the basic syntax, take a look at my blog post.

Claps if you like this. Share if you love this.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade