If you have been trying to uninstall the preinstalled version of ruby, you would have seen that dtrace has a dependency of ruby, and wouldn’t let you uninstall ruby.
In order to solve this, I try to install ruby using rbenv, using the usual commands.
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 2.3.0 (Or the version you want)
rbenv rehash
echo 'export PATH="$HOME/.rbenv/versions/2.3.0/bin:$PATH"' >> ~/.bashrc
Following this, we need to remove the presently version of ruby. I just directly removed it, without thinking about the repercussions. If you want to do the same, just run the following command.
$ sudo rm -rf /usr/ruby
$ rbenv rehash