As previously noted, on a Mac the system ruby is owned by root and it's not safe to install things against that version with sudo. If you do every gem runs as root and that's a security nightmare. DO NOT DO THAT
I'll walk you through my steps since previous answers assume a bit of command line foo and the added details might be of some use to someone.
Double-check we're running the old, system provided ruby
which ruby
/usr/bin/ruby
(that's the system path)
ruby -v
ruby 2.3.7
(the old version)
brew install ruby
or install brew first
at the end of which, the install says:
/usr/local/Cellar/ruby/2.6.3
Make that show up in the path first
PATH=/usr/local/Cellar/ruby/2.6.3/bin:$PATH
Double-check
which ruby
/usr/local/Cellar/ruby/2.6.3/bin/ruby
Double-check version
ruby --version
ruby 2.6.3p62
Make the path update permanent (otherwise you'll have to update the path each time you want to use ruby)
echo PATH=/usr/local/Cellar/ruby/2.6.3/bin:$PATH >> ~/.bash_profile