Skip to main content

Ruby

Install

Do not use Homebrew because it doesn't add it to your path. Doing brew install ruby prints:

ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc

With rbenv and ruby-build

https://github.com/rbenv/rbenv

https://github.com/rbenv/ruby-build

Install rbenv with brew install rbenv. This installs ruby-build, required to build ruby.

To build ruby with ruby-build, also install the required dependencies listed here: brew install openssl@3 readline libyaml gmp autoconf

rbenv

https://rbenv.org

https://github.com/rbenv/rbenv

rbenv --help

Get versions:

rbenv versions
# * system
# 3.4.4

Get current active version:

rbenv version

Prints system or 3.3.0 (set by /Users/albert/.rbenv/version).

Set version:

rbenv global 3.4.4
rbenv local 3.4.4
rbenv shell 3.4.4

List all versions available to install:

rbenv install -L
rbenv install --list-all

List only the latest stable versions available to install:

rbenv install -l

Install specific version:

rbenv install 3.4.4

Uninstall version (docs). Versions are installed at ~/.rbenv/versions. You simply need to delete the directory with rm -rf. Doing rbenv prefix <version> gives you the path, so you can do:

rbenv prefix 3.4.4 | xargs rm -rf

Doing rbenv init adds the following to ~/.zprofile:

# Added by `rbenv init` on Mon Jul 14 11:28:47 CEST 2025
eval "$(rbenv init - --no-rehash zsh)"

If you instead add this to your ~/.zshrc, when you do rbenv shell 3.4.4 it says "rbenv: shell integration not enabled. Run `rbenv init' for instructions.".

CocoaPods

https://cocoapods.org

Install cocoapods: gem install cocoapods. (If using the macOS system ruby, you need to do sudo gem install cocoapods, see https://guides.cocoapods.org/using/getting-started.html#installation.) After installing, doing which pod should output something like /Users/albert/.rbenv/shims/pod. Run pod --version to get the version.

Install dependencies (on a folder with a Podfile):

bundle exec pod install

This creates a Podfile.lock.

gem

https://rubygems.org

Gemfile:

Display information about the RubyGems environment:

gem environment

List all installed gems:

gem list

Install a gem:

gem install <gem-name>
gem install <gem-name> -v <version>
gem install rails -v 8.0.2

Version constraints

https://rubylearning.com/guides/ruby-gems-guide.html

SpecifierExampleMeaning
Exact"2.1.0"Only version 2.1.0
Pessimistic (~>)"~> 2.1"Any version >= 2.1 and < 3.0
Pessimistic (patch)"~> 2.1.0"Any version >= 2.1.0 and < 2.2.0
Greater or equal">= 1.0"Any version 1.0 or higher
Combined">= 1.0", "< 3.0"Between 1.0 (inclusive) and 3.0 (exclusive)

bundle

Ruby Dependency Management

https://bundler.io

https://guides.rubygems.org/getting_started/ - What is Bundler?

Install the exact gem versions.

Bundler reads a Gemfile that declares which gems your project needs, resolves compatible versions, and locks them in a Gemfile.lock (source).

Always commit both Gemfile and Gemfile.lock to version control (source).

important

Gemfile.lock pins Bundler to a version using the BUNDLED WITH section. It's recommended to install Bundler with the same version, like this: gem install bundler -v '4.0.12'. Otherwise, on machines that have an older Bundler major installed, bundle install can fail due to an incompatible Bundler version. Pinning the install command to the lockfile’s Bundler version makes setup deterministic.

Install bundler: gem install bundler -v 4.0.12 or gem install bundler. After installing, doing which bundle should output something like /Users/albert/.rbenv/shims/bundle. After installing, you may get a message like this:

A new release of RubyGems is available: 3.6.9 → 4.0.15!
Run `gem update --system 4.0.15` to update your installation.

Run bundle --version to get the version.

Help:

bundle help

Display detailed help for each subcommand:

bundle help <command>
bundle help install

bundle <command> --help
bundle install --help

Install the gems specified by the Gemfile or Gemfile.lock (docs):

bundle install

Update dependencies to their latest versions (docs):

bundle update

Execute a script in the current bundle (docs):

bundle exec <command>
bundle exec pod install

Show all the gems in your bundle, or the path to a gem (docs):

bundle show
bundle show fastlane