Ruby: Running Code & Tools
Running Ruby
ruby script.rb # run a script
irb # interactive Ruby (REPL)
ruby -e "puts 1 + 1" # run inline code
irb (Interactive Ruby) is your REPL — great for experimenting with expressions and testing syntax.
Editors / IDEs
- VS Code — install the Ruby extension by rebornix (Ruby language support, debugger, linting)
- RubyMine — JetBrains IDE for Ruby (paid, but full-featured with Rails support)
- Vim/Neovim with ruby-lsp for LSP-based autocompletion and diagnostics
Gems (package manager)
Ruby libraries are called gems, distributed via rubygems.org. The gem command manages them:
gem install rails # install a gem
gem list # list installed gems
gem env # show gem environment
Bundler (dependency manager)
Production projects use Bundler to manage gem versions:
gem install bundler # install Bundler
bundle init # create Gemfile
bundle install # install from Gemfile
bundle exec ruby app.rb # run with locked gems
Ruby on Rails
Ruby's most famous framework:
gem install rails
rails new my_app # generate a full Rails app
rails server # start dev server
rails generate model User name:string email:string
rails db:migrate
Testing
Ruby has a strong testing culture:
# test/example_test.rb
require 'minitest/autorun'
class MathTest < Minitest::Test
def test_addition
assert_equal 5, 2 + 3
end
end
Run tests: ruby test/example_test.rb or rails test in a Rails project.
Popular alternative frameworks
| Framework | Use Case |
|---|---|
| Ruby on Rails | Full-stack web apps |
| Sinatra | Lightweight web apps / APIs |
| Rack | Rack middleware / bare HTTP |
| Hanami | Modern, component-based framework |
Quick check below!