Ruby
April 6, 2025 ยท View on GitHub
Dynamically typed open-source programming language known for its simplicity, flexibility, and focus on developer happiness.
Not my main language but it's an easy language to pick up so I've written a few bits and pieces over the years eg. check_puppet.rb.
- Popularity Over the Years
- Poignant Guide to Ruby
- IRB
- Gem
- rbenv
- RVM - Ruby Version Manager
- Code
- Linting
- JRuby
- Ruby IDEs
- Meme
Popularity Over the Years
IMO was at peak popularity in the late 2000s when Puppet was the big thing (Puppet was written in Ruby) and was the first widely used configuration language (CFengine wasn't as widely used).
Update: a quick Google found this article showing Ruby actually peaked in the mid 2000s rather than the late 2000s. I probably should have made more notes here at that time...
Poignant Guide to Ruby
A popular source for learning Ruby.
http://www.rubyinside.com/media/poignant-guide.pdf
IRB
Interactive Ruby interpreter.
(if you need to install the irb Gem see next section)
Start the irb interactive ruby interpreter:
irb
JIRB
JRuby interactive Ruby interpreter.
Start the jirb interactive ruby interpreter:
jirb
GUI irb using swing:
jruby -S jirb_swing
java_import java.lang.System
version = System.getProperties["java.runtime.version"]
Gem
Install Gems
gem install "$name"
Install the mdl gem for markdown linting (used heavily to check the docs in this repo):
gem install mdl
Run mdl to check an .md file:
mdl README.md
Interesting Gems
dotenv- load.envor.envrcfilesirb- Interactive Ruby interpretermdl- Markdown lintlolcat- turns text into rainbow coloursgitlab- GitLab CLIfastlane- see Fastlane docjgrephttpartygistkramdown
List Installed Gems
gem list
Configure gem command to install gems to user writable $HOME/.gem/ruby/<version>/gems/ directory:
In $HOME/.gemrc:
gem: --user-install
gem install then installs to ~/.gem/ruby/<version>/gems.
Then make sure to add $HOME/.gem/ruby/<version>/bin to $PATH environment to be able to run commands installed by
gems:
gem env
Runs server on http://localhost:8808 to show installed gems:
gem server
gem install ruby-debug
gem install cheat
Install from Custom Gem Server
gem install --source http://server
rbenv
rbenv install
Installs to ~/rbenv (RBENV_ROOT):
brew install rbenv
Adds to ~/.bash_profile:
rbenv init
Open a new login shell:
bash -l
or source:
source ~/.bash_profile
rbenv install ruby versions
List installed ruby versions:
rbenv versions
* system
List latest stable versions:
rbenv install -l
List all local versions:
rbenv install -L
Install a Ruby version:
rbenv install 3.4.1
rbenv local
Set the local Ruby version for this directory (creates a .ruby-version file):
rbenv local 3.4.1
Show the local configured version:
rbenv local
Undo the local ruby setting:
rbenv local --unset
rbenv global
Set the global ruby version by setting ~/.rbenv/version:
rbenv global 3.4.1
rbenv shell
Set the Ruby version in the local shell only with environment variable RBENV_VERSION:
rbenv shell 3.4.1
which irb
/Users/hari/.rbenv/shims/irb
rbenv which irb
/Users/hari/.rbenv/versions/3.4.1/bin/irb
rbenv gem
Check your gem is using the rbenv ruby version:
gem env home
/Users/hari/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0
rbenv which gem
/Users/hari/.rbenv/versions/3.4.1/bin/gem
Then gem install as usual:
gem install bundler
rbenv versions
rbenv versions
system
* 3.4.1 (set by /Users/hari/github/.../.ruby-version)
rbenv version
rbenv version
3.4.1 (set by /Users/hari/github/.../.ruby-version)
RVM - Ruby Version Manager
Installs multiple Ruby environments, interpreters and gem commands under
Like VirtualEnv in Python - multiple ruby environments, interpreters and gems
RVM Install
Install GPG Keys:
gpg2 --keyserver keyserver.ubuntu.com \
--recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \
7D2BAF1CF37B13E2069D6956105BD0E739499BDB
On Mac, had to do this instead:
gpg --keyserver hkps://keys.openpgp.org \
--recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \
7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Prompts to import GPG keys if you skipped the step above:
curl -sSL https://get.rvm.io | bash -s stable
or with Ruby-on-Rail (compiles, takes ages):
curl -sSL https://get.rvm.io | bash -s stable --rails
You will likely get a warning to remove the user gem setting from $HOME/.gemrc as it'll clash with RVM:
In $HOME/.gemrc, remove:
gem: --user-install
RVM Usage
See available interpreters:
rvm list known
Install a recent Ruby interpreter:
rvm install ruby
Further help:
rvm help
Code
| Code | Description |
|---|---|
foo | local variable (default: NameError: undefined local variable exception) |
$foo | global variable (default: nil) |
@foo | instance variable (default: nil) |
@@foo | class variable (default: NameError exception) |
^[A-Z]... | constant (default: NameError exception) |
puts object.inspect
object.to_yaml
Path to code modules:
$LOAD_PATH
Linting
Rubocop
gem install rubocop
rubocop
Auto-correct the file(s) at your own peril:
(make sure you git commit before running this to see the changes / revert)
rubocop -a
will annoyingly space all:
#comment_out_code
lines to
# comment_out_code
but where they are opening blocks it won't indent the block contents to stay aligned by 2 space indents:
# lane :build do |options|
# puts "Building version #{options[:version]}"
# end
JRuby
Run Ruby on the Java JVM with full access to Java libraries.
See also Jython.
Personally, I much prefer Groovy.
Use Java library jar:
require '/path/to/my.jar'
Not needed in jirb (JRuby's interactive interpreter):
require 'java'
import java.lang.System
Newer safer way to import from Java:
java_import java.lang.System
version = System.getProperties["java.runtime.version"]
this does equiv of: import org.xxx.yyy and includes *:
include_package "org.xxx.yyy"
Rubinius
JIT for Ruby
Ludicrous
http://rubystuff.org/ludicrous/
JIT for Ruby
Experimental last I checked and performance roughly on par with YARV (Yet Another Ruby VM bytecode interpreter) which has since been merged into official Ruby 1.9 interpreter 2007.
Ruby IDEs
RubyMine
https://www.jetbrains.com/ruby/
Ruby-specific IDE by Jebrains, based off IntelliJ IDEA.
Unfortuntely, this is proprietary paid for only and doesn't have a free version like PyCharm or main IntelliJ.
Alternatives
VS Code, Sublime or Gleany.
See Editors & IDEs page.
Meme
Porting Your Language to the JVM

Ported from private Knowledge Base page 2012+