First install the necessary OS packages

sudo -i
apt-get install libyaml-dev libreadline-dev libxml2-dev libxslt1-dev libsqlite3-dev libssl-dev libreadline6-dev libncurses5-dev libffi-dev

# A lot of fileuploader gems need this
apt-get install  libmagickcore-dev libmagickwand-dev libmysqlclient-dev
PKG_CONFIG_PATH='/usr/lib/x86_64-linux-gnu/pkgconfig' gem install rmagick

# postgre db for Rails projects
apt-get install libpq-dev postgresql

# Install git
apt-get install git

Now using your regular account (no sudo), change to your home directory and install rbenv

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

Next install ruby-build plugin to compile and install different versions of Ruby with the help of rbenv

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Finally to manage environment variables, which is used to load passwords and secrets into an application at runtime, use the rbenv-vars plugin.

To install the rbenv-vars plugin clone it like ruby-build.

git clone https://github.com/sstephenson/rbenv-vars.git ~/.rbenv/plugins/rbenv-vars