RVM is a great tool to manage your ruby versions and set up your working environment.
Assuming you already have RVM installed, to get the latest version of ruby, which is needed for these examples, open a terminal and run:
$ rvm get stable
$ rvm install ruby --latest
Check your ruby version by running:
$ ruby -v
> ruby 2.3.0p0
To install Rails 5, first create a new gemset using the latest ruby version and then install rails:
$ rvm use ruby-2.3.0@my_app --create
$ gem install rails
To check your rails version, run:
$ rails -v
> Rails 5.0.0