How To Use Ruby In Vscode

Visual Studio Code (VSCode) has quickly become one of the most popular code editors among developers. Its flexibility, lightweight nature, and powerful features make it an excellent choice for programming in a variety of languages. In this blog post, we will discuss how to use Ruby within VSCode to create a smooth, efficient development workflow.


Before diving into the setup process, ensure that you have the following installed on your machine:

  • Ruby: Download and install the latest version of Ruby for your operating system.
  • Visual Studio Code: Download and install the latest version of VSCode for your operating system.

Setting up Ruby in VSCode

Follow the steps below to set up Ruby in VSCode:

Step 1: Install the Ruby Extension

To use Ruby with VSCode, you will need to install the Ruby extension by Peng Lv. This extension provides enhanced Ruby language and debugging support.

To install the Ruby extension, open the Extensions sidebar in VSCode by clicking on the square icon on the left-hand side or pressing Ctrl+Shift+X. In the search bar, type “Ruby” and look for the extension by Peng Lv. Click the green Install button to add it to your editor.

Step 2: Configure the Extension

Once the Ruby extension is installed, you may need to configure it to work with your specific Ruby installation. Open the VSCode settings by clicking on the gear icon in the lower left corner and selecting Settings. In the search bar, type “Ruby” to filter the available settings.

The most important setting to configure is the Ruby Path. This should point to the location of your Ruby executable. By default, the extension will attempt to use the Ruby installation found in your system’s PATH variable. However, if you need to specify a custom path, you can do so in this setting.

For example, if your Ruby executable is located at /usr/local/bin/ruby, your setting should look like this:

    "ruby.rubyPath": "/usr/local/bin/ruby"

Step 3: Write and Execute Ruby Code

With the Ruby extension installed and configured, you can now write and execute Ruby code within VSCode. Create a new file with the extension .rb and start writing your Ruby code.

To execute the code, you can use the built-in terminal in VSCode. Open the terminal by clicking on Terminal in the top menu and then New Terminal, or press Ctrl+`. In the terminal, type ruby followed by the path to your Ruby file and press Enter.

For example, if your Ruby file is called hello_world.rb and is located in your current working directory, you would type:

ruby hello_world.rb


Setting up Ruby in VSCode is a simple process that only requires a few steps. By installing the Ruby extension by Peng Lv and configuring it to work with your Ruby installation, you will have a powerful development environment for writing and executing Ruby code. Happy coding!