Ruby not installing properly

I am trying to install Ruby on my new Mac Studio and I am running into an issue moving past the Jekyll installation steps… I seem to have the latest Ruby version but when I run a command to see which version I have, it gives me a 2022 version.

Any help greatly appreciated.

I had a similar issue and I had to run rbenv or chmod to get into the right version of Ruby.

macs seem to come with a system ruby, seems to cause lots of issues.

I think rbenv is a ruby manager that allows you to switch between different versions. Look in to what commands you can use with it - one is probably list to see what versions are available and then there should be a way to tell it which one you want to set it to?

I wrote about installing Ruby with rbenv in a post in my blog, but sharing the useful part here. Note that this is for linux, so some adaptations might be needed.


For those familiar with Python, rbenv is similar to pyenv. To install rbenv, run the following commands:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src

This will download the rbenv repository to your home directory, and then compile it. Next, add the following lines to your ~/.bashrc file:

# enable rbenv
if [ -d "$HOME/.rbenv/" ]; then
    export PATH="$HOME/.rbenv/bin:$PATH"
    eval "$(rbenv init - bash)"
fi

Then, restart your terminal or run . ~/.bashrc to reload your bash settings. This will make the rbenv command available in your terminal. To test if this is working properly, run curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash. It should output something similar to this:

Checking for `rbenv' in PATH: /home/gca/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: Not found
Checking `rbenv install' support: /home/gca/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20220910.1-10-gecb9d22)
Counting installed Ruby versions: 1 versions
Auditing installed plugins: OK

It will display an error in line Checking for rbenv shims in PATH. Don’t worry, this will be fixed. Next, you need to install ruby-build as a rbenv plugin, so you can easily download and install different versions of Ruby. To do so, run the following commands:

mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

To check which versions of Ruby are available to install, simply run rbenv install --list. You can install any version you want, but I recommend installing the latest stable version. At the time of writing, it is version 3.1.2. To install it, you need first to install the ssl dependency and then the Ruby version.

sudo apt install -y libssl-dev
rbenv install 3.1.2

Because macOS comes with its own (old) version of Ruby, Homebrew does not automatically put Homebrew-Ruby on its default path (i.e. Ruby is a “keg-only” in Homebrew parlance).

When you install/re-install ruby, Homebrew will provide instructions for how to add its Ruby to the path. Below is an example re-install. Note that the exact details will vary depending on your OS/processor/shell/etc:

% brew reinstall ruby
...
==> Pouring ruby--3.3.6.sonoma.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/3.3.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
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="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc