Setup a Rails 4.1 Development Environment on Ubuntu 14.04

This tutorial shows you how to setup a Ruby on Rails 4.1 development environment on Ubuntu 14.04. It covers using rbenv to manage your ruby environments as well as how to set it up using a different database such as postgres.

Here is the code used in the tutorial.

# install packages
sudo apt-get -y install git-core curl build-essential zlib1g-dev libssl-dev libreadline-dev libxml2-dev libxslt1-dev nodejs sqlite3 libsqlite3-dev postgresql postgresql-server-dev-9.3 pgadmin3

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

# install ruby-build
git clone git:// ~/.rbenv/plugins/ruby-build

# choose version and install ruby
rbenv install -l
rbenv install 2.1.4
rbenv global 2.1.4
rbenv rehash
ruby -v

# optional, exclude documentation
echo "gem: --no-ri --no-rdoc" > ~/.gemrc

# install rails 
gem install rails
rbenv rehash

# setup postgres user
sudo -u postgres createuser creston -s

# create your first rails application
mkdir apps
cd apps
rails new testapp -d postgresql
cd testapp
bin/rake db:create db:migrate
bin/rails s

Please go ahead and leave a comment below if you have any questions about this tutorial.