[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
- Download the installer from RubyInstaller. Choosing the "WITH DEVKIT" version also supports building native extensions.
- Run the installer and follow the on-screen instructions. Make sure to check "Add Ruby executables to your PATH".
- 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
| Tool | Description |
|---|---|
| Visual Studio Code | Installing the Ruby extension adds code completion and syntax checking. |
| RubyMine | JetBrains' Ruby-specific IDE. Offers rich debugging features. |
| Sublime Text / Vim | Lightweight 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 contact us.