So I’m just off a fresh install of Ubuntu 10.10 and I thought I might as well document the process of how I setup my Rails development environment. I’m still learning RVM best practices so constructive criticism is welcome. So here goes…
Ruby
# Install ruby, etc.
sudo apt-get install irb libopenssl-ruby libreadline-ruby rdoc ri ruby ruby-dev build-essential bison openssl libreadline5 libreadline-dev curl zlib1g zlib1g-dev libssl-dev libxml2-dev
Vim & GVim
# Install vim and gvim
sudo apt-get install vim vim-gnome
GIT
# Install git and gitg repo viewer
sudo apt-get install git git-doc gitg
# Set name and email in gitconfig
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
# Configure default git text editor
git config --global core.editor "gvim --nofork"
# Configure 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
# Generate SSH keys (provide a good passphrase when asked)
ssh-keygen -t rsa -C "johndoe@example.com"
# Add git aliases
echo "alias gb='git branch'" >> ~/.bashrc
echo "alias gc='git commit -v'" >> ~/.bashrc
echo "alias gca='git commit -a -v'" >> ~/.bashrc
echo "alias gco='git checkout'" >> ~/.bashrc
echo "alias gd='git diff'" >> ~/.bashrc
echo "alias gdc='git diff --cached'" >> ~/.bashrc
echo "alias gdh='git diff HEAD'" >> ~/.bashrc
echo "alias gp='git push'" >> ~/.bashrc
echo "alias gl='git pull'" >> ~/.bashrc
echo "alias gpr='git pull --rebase'" >> ~/.bashrc
echo "alias gst='git status'" >> ~/.bashrc
echo "alias gap='git add -p'" >> ~/.bashrc
echo "alias glg='git log --pretty=oneline --abbrev-commit'" >> ~/.bashrc
# Setup git bash completion
cd ~/
git clone git://git.kernel.org/pub/scm/git/git.git
mv git/contrib/completion/git-completion.bash ~/.git-completion.sh
rm -rf ~/git
echo "export GIT_PS1_SHOWDIRTYSTATE=1" >> ~/.bashrc
echo "export GIT_PS1_SHOWSTASHSTATE=1" >> ~/.bashrc
echo "source ~/.git-completion.sh" >> ~/.bashrc
# Add git info to PS1 (append this to your ~/.bashrc file, not commented)
# PS1='[\[\033[1;34m\]\u\[\033[0m\]@\h \W$(__git_ps1 "(%s)")]\$ '
RubyGems
# Download and install RubyGems
cd ~/
wget http://production.cf.rubygems.org/rubygems/rubygems-1.5.2.tgz
tar xzf rubygems-1.5.2.tgz
cd rubygems-1.5.2
sudo ruby setup.rb
# Link gem command to 1.8 version
sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1
# Turn off rdoc generation when installing/updating gems
echo "install: --no-ri --no-rdoc" >> ~/.gemrc
echo "update: --no-ri --no-rdoc" >> ~/.gemrc
RVM
# RVM install
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
# Load RVM into shell
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
# RVM bash completion complete
echo '[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion' >> ~/.bashrc
# One-time source of RVM
source ~/.rvm/scripts/rvm
# Verify RVM installation
rvm -v
# Install latest stable 1.8.7 release
rvm install 1.8.7
# Set default ruby
rvm --default 1.8.7
# Install more rubies
rvm install ree
rvm install 1.9.2
At this point, you should have everything “installed”. From here, it’s more of a preference on how you want to use rvm. Since I work with both Rails2.3 and Rails3, I like to create a rails2 gemset and a rails3 gemset from which I can create new projects from. After new projects are created, I create the project rvmrc file to then build from.
RVM Gemsets
# Create some rails specific gemsets
rvm gemset create rails2
rvm gemset create rails3
# Switch to ruby 1.8.7-p334 with gemset rails2
rvm 1.8.7-p334@rails2
# Install rails 2.3.11
gem install rails -v=2.3.11; gem install ruby-debug
# Switch to ruby 1.8.7-p334 with gemset rails3
rvm 1.8.7-p334@rails3
# Install rails 3
gem install rails ruby-debug
# Create project specific .rvmrc
cd ~/projects
echo "rvm --create use 'ruby-1.8.7-p334@example_app'" > ~/projects/example_app/.rvmrc
Databases
# Install sqlite and deps
sudo apt-get install libsqlite3-0 libsqlite3-dev sqlite3
gem install sqlite3-ruby
# Install mysql and deps
sudo apt-get install mysql-client mysql-server libmysqlclient-dev
gem install mysql
# Install postgresql and deps
sudo apt-get install postgresql libpq-dev
gem install pg
RDoc
Build a custom rdoc package and download it for use locally
# Download rdoc's to use locally
http://railsapi.com