Install compiler toolchain and some useful tools.

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev gnupg build-essential libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

For bare minimum installation, just install:

sudo apt-get install curl gnupg build-essential

There are a few ways to install ruby, such as rvm and rbenv. We will be using rbenv here. Change the ruby version number to the version that you intend to install. You can check latest and available versions here.

cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

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

rbenv install 2.2.5
rbenv global 2.2.5

Install the following 2 ruby gems after you have ruby installed. Again, please change the version number to whichever you want to install.

echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
gem install rails -v 4.2.7
rbenv rehash

Next, you will need to setup the database client that you are using. For sqlite:

sudo apt-get install libsqlite3-dev sqlite3

For MySQL:

sudo apt-get install libmysqlclient-dev mysql-client