Ruby 3 cheatsheet

Ruby 3: Command line and gems

9 common Ruby 3 tasks.

Check the Ruby version

Print the installed Ruby version.

ruby -v

Run a script

Run a Ruby file from the command line.

ruby script.rb

Run a one-line command

Evaluate code from the command line.

ruby -e 'puts (1..5).sum'

Open the interactive shell

Start IRB, the interactive Ruby shell.

irb

Install a gem

Install a library from RubyGems.

gem install rack

Start a Gemfile

Create a Gemfile for a project's dependencies.

bundle init

Install the bundle

Install the gems listed in the Gemfile and record exact versions in Gemfile.lock.

bundle install

Run a command with the bundle

Run a command using the gem versions in Gemfile.lock.

bundle exec rspec

Lint the code

Check style and common mistakes with RuboCop. Add -a to fix what is safe.

bundle exec rubocop

Was this page helpful?