Installing Ruby with rbenv on macOS

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install rbenv

brew install rbenv
==> Downloading https://ghcr.io/v2/homebrew/core/rbenv/manifests/1.3.0-1
##################################################################################################################################################################### 100.0%
==> Fetching dependencies for rbenv: m4, autoconf, libyaml, ca-certificates, openssl@3, pkg-config, readline and ruby-build
==> Downloading https://ghcr.io/v2/homebrew/core/m4/manifests/1.4.19
##################################################################################################################################################################### 100.0%
==> Fetching m4
==> Downloading https://ghcr.io/v2/homebrew/core/m4/blobs/sha256:8434a67a4383836b2531a6180e068640c5b482ee6781b673d65712e4fc86ca76
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/autoconf/manifests/2.72-1
##################################################################################################################################################################### 100.0%
==> Fetching autoconf
==> Downloading https://ghcr.io/v2/homebrew/core/autoconf/blobs/sha256:32c6ff07058a61e7fada66d171fee246502fcd1f5b98b65a1ef5b0acfcfa28c2
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/manifests/0.2.5
##################################################################################################################################################################### 100.0%
==> Fetching libyaml
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/blobs/sha256:4d6e02ce3a82b60033bc7e55bef841dcfef0c05c051176d96accb50744136c6d
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2024-07-02-1
##################################################################################################################################################################### 100.0%
==> Fetching ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:efae38787c286c7a249f9e7158e3159107a361df5e68fc2a531ccb8177b01cbe
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.3.2
##################################################################################################################################################################### 100.0%
==> Fetching openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/blobs/sha256:39bc60aa67712dcf946d0465c7f9d838deb5623834dd5229c9ce9621214cc21e
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pkg-config/manifests/0.29.2_3
##################################################################################################################################################################### 100.0%
==> Fetching pkg-config
==> Downloading https://ghcr.io/v2/homebrew/core/pkg-config/blobs/sha256:421571f340277c62c5cc6fd68737bd7c4e085de113452ea49b33bcd46509bb12
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/readline/manifests/8.2.13
##################################################################################################################################################################### 100.0%
==> Fetching readline
==> Downloading https://ghcr.io/v2/homebrew/core/readline/blobs/sha256:0cf2cae0b9bb71bee1f9f9b3ab1e5dfc27b32f474db7f2d38b8b2dffd02da5ff
##################################################################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ruby-build/manifests/20240917
##################################################################################################################################################################### 100.0%
==> Fetching ruby-build
==> Downloading https://ghcr.io/v2/homebrew/core/ruby-build/blobs/sha256:a69d04a25971f1f19d4cc2893adafc60e472dbb2fca2799ebf6de25d2e5e1658
##################################################################################################################################################################### 100.0%
==> Fetching rbenv
==> Downloading https://ghcr.io/v2/homebrew/core/rbenv/blobs/sha256:8c1ae8d76748e0140a458cd4c83b2f6ed83da17777940f7878ce5348ede8aeff
##################################################################################################################################################################### 100.0%
==> Installing dependencies for rbenv: m4, autoconf, libyaml, ca-certificates, openssl@3, pkg-config, readline and ruby-build
==> Installing rbenv dependency: m4
==> Downloading https://ghcr.io/v2/homebrew/core/m4/manifests/1.4.19
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/5b2a7f715487b7377e409e8ca58569040cd89f33859f691210c58d94410fd33b--m4-1.4.19.bottle_manifest.json
==> Pouring m4--1.4.19.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/m4/1.4.19: 14 files, 742.5KB
==> Installing rbenv dependency: autoconf
==> Downloading https://ghcr.io/v2/homebrew/core/autoconf/manifests/2.72-1
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/1b54b8d75974d006eb6be1db91a6ec040791ac751f25271fcd5a1d78cb361afd--autoconf-2.72-1.bottle_manifest.json
==> Pouring autoconf--2.72.sonoma.bottle.1.tar.gz
🍺  /usr/local/Cellar/autoconf/2.72: 72 files, 3.6MB
==> Installing rbenv dependency: libyaml
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/manifests/0.2.5
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/5f6b0af1730aa1bc02f8021c90ed7ffe988eeba95eec83e6c828f77332ba6406--libyaml-0.2.5.bottle_manifest.json
==> Pouring libyaml--0.2.5.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/libyaml/0.2.5: 11 files, 333.8KB
==> Installing rbenv dependency: ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2024-07-02-1
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/70833b1debbd42ccd563134452c4150a0ed85737bc1bb0ceab98b4300991192d--ca-certificates-2024-07-02-1.bottle_manifest.json
==> Pouring ca-certificates--2024-07-02.all.bottle.1.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /usr/local/Cellar/ca-certificates/2024-07-02: 4 files, 231.3KB
==> Installing rbenv dependency: openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.3.2
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/15a43beab5e5017b1a9fe7584ff44a48195632fd196c23ee0e5e7ecf67e9ef2a--openssl@3-3.3.2.bottle_manifest.json
==> Pouring openssl@3--3.3.2.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/openssl@3/3.3.2: 6,984 files, 32.9MB
==> Installing rbenv dependency: pkg-config
==> Downloading https://ghcr.io/v2/homebrew/core/pkg-config/manifests/0.29.2_3
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/ac691fc7ab8ecffba32a837e7197101d271474a3a84cfddcc30c9fd6763ab3c6--pkg-config-0.29.2_3.bottle_manifest.json
==> Pouring pkg-config--0.29.2_3.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.29.2_3: 12 files, 659KB
==> Installing rbenv dependency: readline
==> Downloading https://ghcr.io/v2/homebrew/core/readline/manifests/8.2.13
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/aa1afa38997a2866d91c81fdda8b36d436cd4ea7a82aed07d13c83c56eb3460e--readline-8.2.13.bottle_manifest.json
==> Pouring readline--8.2.13.sonoma.bottle.tar.gz
🍺  /usr/local/Cellar/readline/8.2.13: 51 files, 1.6MB
==> Installing rbenv dependency: ruby-build
==> Downloading https://ghcr.io/v2/homebrew/core/ruby-build/manifests/20240917
Already downloaded: /Users/admin/Library/Caches/Homebrew/downloads/7447723f460499987a50d5eaea45085cbb99517a5fa41a36eec4e30e96a7cbfb--ruby-build-20240917.bottle_manifest.json
==> Pouring ruby-build--20240917.all.bottle.tar.gz
🍺  /usr/local/Cellar/ruby-build/20240917: 625 files, 342.7KB
==> Installing rbenv
==> Pouring rbenv--1.3.0.all.bottle.1.tar.gz
==> Caveats
zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/rbenv/1.3.0: 36 files, 73.5KB
==> Running `brew cleanup rbenv`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> rbenv
zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

Add the following to ~/.zshrc file:

eval "$(rbenv init -)"

Apply the changes:

source ~/.zshrc

Verify the installation:

type rbenv
rbenv is a shell function from /Users/admin/.zshrc

Install Ruby

rbenv install -l
3.1.6
3.2.5
3.3.5
jruby-9.4.8.0
mruby-3.3.0
picoruby-3.0.0
truffleruby-24.1.0
truffleruby+graalvm-24.1.0

Only latest stable releases for each Ruby implementation are shown.
Use `rbenv install --list-all' to show all local versions.
rbenv install 3.3.5
ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.3.5.tar.gz...
-> curl -q -fL -o ruby-3.3.5.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.5.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.1M  100 21.1M    0     0  5937k      0  0:00:03  0:00:03 --:--:-- 5938k
==> Installing ruby-3.3.5...
ruby-build: using libyaml from homebrew
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.5" --with-openssl-dir=/usr/local/opt/openssl@3 --enable-shared --with-libyaml-dir=/usr/local/opt/libyaml --with-ext=openssl,psych,+
-> make -j 8
-> make install
==> Installed ruby-3.3.5 to /Users/admin/.rbenv/versions/3.3.5

NOTE: to activate this Ruby version as the new default, run: rbenv global 3.3.5
rbenv global 3.3.5
source ~/.zshrc
ruby -v
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-darwin23]

Leave a Reply

Your email address will not be published. Required fields are marked *