Skip to content

Instantly share code, notes, and snippets.

@hyeomans
Forked from alexbihary/gist:5078409
Last active December 15, 2015 21:39
Show Gist options
  • Save hyeomans/5327710 to your computer and use it in GitHub Desktop.
Save hyeomans/5327710 to your computer and use it in GitHub Desktop.
Setting up an environment in Debian based

Ubuntu 12.04 Ruby on Rails Development Environment

I haven't set up an install guide for the latest ubuntu release, largely because the last set of instructions worked pretty closely with the latest and greatest Ubuntu, 12.04 Precise Pangolin, however when installing today, I found that there were enough differences in the way that I configure my setup to justify an update, so here it goes. Yes, I'm late to the party, but a quick google search didn't find anything that I felt was as complete for my requirements as my previous install guides, so here I go.

As always with my install guides, I have included here is just about everything you'll need (and then some) to get started with ruby on rails development with Ubuntu 12.04 as a platform. These are my settings and preferences, and this is certainly not the only way of doing things, so keep that in mind.

Step 1: Get the repos ready and run updates.

sudo apt-get update && sudo apt-get upgrade

Common Libraries.

sudo apt-get install curl
curl -L get.rvm.io | bash -s stable --auto
. ~/.bash_profile
rvm requirements

sudo apt-get install -y autoconf automake bison build-essential curl exuberant-ctags gcc git-core git-doc gitg imagemagick libc6-dev libffi-dev libgdbm-dev libmagickwand-dev libncurses5-dev libnotify-bin libpq-dev libreadline-dev libreadline6 libreadline6-dev libsqlite3-0 libsqlite3-dev libssl-dev libtool libxml2-dev libxslt-dev libxslt1-dev libyaml-dev make ncurses-dev ncurses-term openssl patch pgadmin3 pkg-config postgresql postgresql-contrib sqlite3 ssh subversion tmux vim zlib1g zlib1g-dev software-properties-common python-software-properties zip unzip

rvm install 2.0.0
rvm install 1.9.3
rvm install 1.8.7
rvm --default use 2.0.0-p0

gem install rails



sudo apt-get install 
sudo apt-get install vim git-core gitg tmux

Step 2: Add required applications.

sudo apt-get install 

Step 2.1: Add databases.

Postgres

sudo apt-get install 
sudo -u postgres createuser --superuser `logname`

MySQL

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

###SQLite

sudo apt-get install 

Step 3: Configure github, because you know everyone is using github.

git config --global user.name git-username
git config --global user.email git-email-address
ssh-keygen -t rsa -C git-email-address

Add public key to github then test it out with this

ssh -T [email protected]

Set default text editor for git

git config --global core.editor vim

Set git status colors

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.status.changed yellow
git config --global color.status.added green
git config --global color.status.untracked red

Verify git settings

git config --list

If you have a github account, you should already know how to add the key that you just generated to your github account. If you don't, please consult github as their documentation is better than mine is. LINK

Step 4: Install RVM, Ruby and Rails

This one has actually changed a little bit. You can really go about things the same way as you always did, however you can also run one command and install rvm, ruby 1.9.3 and the latest version of rails, which at the time of this post was 3.2.6.

curl -L https://get.rvm.io | bash -s stable --rails
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
source .bashrc

Using rbenv

Install rbenv

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

Install ruby-build

mkdir ~/.rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
exec $SHELL

Install some rubies

rbenv install 1.9.2-p320
rbenv install 1.9.3-p194
rbenv rehash

Set a global ruby

rbenv global 1.9.2-p320

Turn off rdoc generation when installing/updating gems

echo "install: --no-ri --no-rdoc" >> ~/.gemrc
echo "update: --no-ri --no-rdoc" >> ~/.gemrc

That's kind of it. You've got a running development environment, but I never stop with just the minimum, and neither should you!

##Step 5: Install NodeJS and NPM sudo apt-get install -y python-software-properties python g++ make sudo apt-get install software-properties-common sudo apt-get update sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs

Step 6: Setting up postgres for your rails app access

At this point, postgresql is set up, however you will need to also configure it for each application that you wish to host on postgresql, so the following steps you will need to repeat for each new application.

sudo su postgres

# Create a role for your application #
# Substitute myapp with your app name and password with your password #
# Semi-colons are important! #

psql template1 #starts Postgres interactive shell
create role myapp with

createdb login password '_password_'; 
select * from pg_user; # Verify user created ("\q" to exit!)
select * from pg_shadow; # sysid and password hash listed here
\l # list databases
\q # exit Postgres shell
exit # exit "Postgres" admin user

# Configure Postgres to use this user for your application #
sudo gedit /etc/postgresql/9.1/main/pg_hba.conf 

Scroll down in this file and add the following just before: local all all ident

local postgres myapp md5
local "myapp_development" myapp md5
local "myapp_test" myapp md5
local "myapp_production" myapp md5

Now, just restart postgres and make sure your database.yml and Gemfile.rb are configured correctly and you should be all set.

sudo /etc/init.d/postgresql restart

### database.yml a rails app using Postgres ###
development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  username: myapp
  password: password

test:
  adapter: postgresql
  encoding: unicode
  database: myapp_test
  pool: 5
  username: myapp
  password: password

production:
  adapter: postgresql
  encoding: unicode
  database: myapp_production
  pool: 5
  username: myapp
  password: password

Add postgres to your Gemfile

Add: gem 'pg'

With this done, you should have a fully functioning rails development environment on ubuntu 12.04. At this point, assuming you've made all of the necessary substitutions, you should be able to go into your rails app and execute a rake db:create:all. But if you are interested in adding some more tools to your setup, and really get things moving using some of these extras!

Development Extras

Add Gedit-Gmate

sudo apt-add-repository ppa:ubuntu-on-rails/ppa
sudo apt-get update
sudo apt-get install gedit-gmate

Add Sublime Text 2

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text-2-beta

Add Retext 1.0 (markdown editor)

sudo add-apt-repository ppa:mitya57
sudo apt-get update
sudo apt-get install retext

Configure Vim for Rails

curl -Lo- https://bit.ly/janus-bootstrap | bash

Add some bash aliases for ease of use

I always add a few bash aliases that make my time at the command line a bit easier, but they only work if you know them, so if any of these appeal to you, feel free to add them, or add to them in the comments!

To make the changes, just enter:

gedit ~/.bashrc

Then enter the following at the bottom of the file.

alias b="bundle"
alias bu="b update"
alias be="b exec"
alias compile="be rake assets:precompile"
alias edit="sublime-text-2"

function commit { be rake assets:precompile git add . read -p "Commit description: " desc git commit -m "$desc" git push }

function newdb { be rake db:drop:all be rake db:create:all be rake db:setup be rake db:test:prepare }

In conclusion...

Be sure to check out the livereload plugin for your browser, if you installed the gem, it only makes sense to get it setup on your system. Plugins exist for both Firefox and Google Chrome, which are the two browsers that I use frequently on Ubuntu.

If you've got any other tips or tools that you use while developing ruby on rails applications on an Ubuntu 11.10 platform, please feel free to add to the comments. Posted by Eric Proctor at 11:45 AM

Labels: 12.04, how-to, precise pangolin, ruby on rails, ubuntu

Source: http://www.rubypluspl.us/2012/06/ubuntu-1204-ruby-on-rails-development.html?utm_source=rubyweekly&utm_medium=email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment