Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

Ruby Dictionary

  1. Home
  2. Ruby Dictionary
  3. [Setup] Ruby Development Environment

[Setup] Ruby Development Environment

This page walks you through setting up a Ruby development environment. macOS comes with Ruby pre-installed, so you can get started right away.

Setting Up on Windows

  1. Download the installer from RubyInstaller. Choosing the "WITH DEVKIT" version also supports building native extensions.
  2. Run the installer and follow the on-screen instructions. Make sure to check "Add Ruby executables to your PATH".
  3. Run the following in Command Prompt to verify the installation.
ruby --version

If version information is displayed, the installation is complete.

Setting Up on macOS

macOS comes with Ruby pre-installed. You can verify it by running the following in Terminal.

ruby --version

If you want the latest version, you can install it using Homebrew or rbenv.

To install with Homebrew:

brew install ruby

To manage versions with rbenv:

brew install rbenv
rbenv install 3.3.0
rbenv global 3.3.0

Using rbenv lets you switch Ruby versions per project.

Running a Program

1. Create the source file

Use a text editor to create a file named hello.rb with the following content.

puts "Hello, World!"
puts "The Ruby environment is set up successfully."

2. Run

ruby hello.rb

If Hello, World! and The Ruby environment is set up successfully. are displayed, you're all set.

Interactive Mode (irb)

irb (Interactive Ruby) lets you try Ruby code one line at a time. It is handy for quick checks.

irb

Once started, a prompt appears. Enter code and the result is returned immediately.

irb(main):001:0> 1 + 2
=> 3
irb(main):002:0> "Hello".length
=> 5
irb(main):003:0> exit

Type exit or press Ctrl + D to quit irb.

Choosing an Editor

ToolDescription
Visual Studio CodeInstalling the Ruby extension adds code completion and syntax checking.
RubyMineJetBrains' Ruby-specific IDE. Offers rich debugging features.
Sublime Text / VimLightweight editors with built-in Ruby syntax highlighting.

If the Command Is Not Found

If your terminal displays ruby: command not found, the PATH may not be configured correctly. Follow the steps below to check and fix the issue.

1. Find the command location

Check where the command is located.

which ruby
which irb

If not found, check common installation locations.

ls /usr/local/bin/ruby
ls /opt/homebrew/bin/ruby

2. Check which shell you are using

echo $SHELL

If /bin/zsh is shown, edit ~/.zshrc; if /bin/bash is shown, edit ~/.bashrc.

3. Add to PATH

Once you know the command location, add the PATH to your shell configuration file.

For macOS (zsh):

echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

For Linux (bash):

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

If you are using rbenv

If Ruby installed via rbenv is not found, the shell initialization may be missing. Add the following to your shell configuration file.

For macOS (zsh):

echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc

For Linux (bash):

echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

For Windows, go to "Advanced System Settings" → "Environment Variables" → "Path" to add the entry. If you used RubyInstaller and checked "Add Ruby executables to your PATH" during installation, this is set automatically.

If you find any errors or copyright issues, please .