DEV Community

Koji Toyota
Koji Toyota

Posted on

The way I installed Ruby on my mac

Prerequisite

Please install Homebrew(official) on your mac.

Install rbenv and ruby-build

At first, I recommend you to install rbenv and ruby-build. They enables you to control Ruby versions flexibly.

brew install rbenv ruby-build
Enter fullscreen mode Exit fullscreen mode

Although I heard that this way tends to yield(don't catch up with the newest version of ruby), it is simple.

Initialize rbenv

Just execute below

rbenv init
Enter fullscreen mode Exit fullscreen mode

This command will add eval "$(rbenv init -)" to your ~/.bash_profile.
Please check it like this

less ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

If you can't find out the line export PATH="$HOME/.rbenv/bin:$PATH" and eval "$(rbenv init -)", please add it by yourself.

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Enter fullscreen mode Exit fullscreen mode

After that, restart your terminal or reload your .bash_profile with this command.

source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

And you can check you could install rbenv or not by this command

rbenv -v
Enter fullscreen mode Exit fullscreen mode

This command will return the version of rbenv

Choose the ruby version and install it.

OK, now we can get the list of the versions of Ruby with below.

rbenv install -l
Enter fullscreen mode Exit fullscreen mode

This time, I assume that we chose 2.5.0 as the target.

rbenv install 2.5.0
Enter fullscreen mode Exit fullscreen mode

Many commands will be executed.
After they are finished, try this.

rbenv versions
Enter fullscreen mode Exit fullscreen mode

and you can get like this

* system
  2.5.0
Enter fullscreen mode Exit fullscreen mode

This indicates you have Ruby 2.5.0 but you are using the pre-installed Ruby.
So, let's change to the target ruby with below

rbenv global 2.5.0
Enter fullscreen mode Exit fullscreen mode

Check your rbenv

For now, your mac is ready to use the Ruby 2.5.0, but I recommend you to check the status of your rbenv.

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Enter fullscreen mode Exit fullscreen mode

This will indicate the install status of rbenv.

Top comments (4)

Collapse
 
johand profile image
Johan • Edited

To prevent installing documentation for gems

touch ~/.gemrc

Inside of this file

install: -N
update: -N

Now your gem install and gem update --system && gem update be more faster avoiding install or updating documentation for the gems

Collapse
 
toyotarone profile image
Koji Toyota • Edited

Hi Johan!
Thank you for your comment.
Avoiding the installation of documents is a good idea. It takes much time.
I will introduce your suggestion to my environment!

Collapse
 
johand profile image
Johan

Excellent!

Collapse
 
israelgonzalezb profile image
Israel Gonzalez-Brooks

You saved me! Your explanation has the additional information that avoids issues with the Mac system ruby version that tripped me up for a little while. Thanks a lot : )