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 0: User Setup (from root login)
sudo adduser <username>
sudo adduser <username> sudo
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install curl
curl -L get.rvm.io | bash -s stable --auto
. ~/.bash_profile
rvm requirements
sudo apt-get install git-core patch gcc make libc6-dev libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf libc6-dev libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
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 build-essential libreadline-dev libssl-dev zlib1g-dev libxml2-dev libxslt-dev
sudo apt-get install vim git-core gitg tmux
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion ruby ncurses-term mercurial ruby-dev exuberant-ctags libnotify-bin make automake ssh openjdk-6-jdk git-core git-doc imagemagick vim vim-rails vim-gnome
sudo apt-get install postgresql postgresql-contrib libpq-dev pgadmin3
sudo -u postgres createuser --superuser `logname`
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
###SQLite
sudo apt-get install sqlite3 libsqlite3-dev libsqlite3-0
git config --global user.name git-username
git config --global user.email git-email-address
ssh-keygen -t rsa -C git-email-address
ssh -T [email protected]
git config --global core.editor vim
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
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
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
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
mkdir ~/.rbenv/plugins
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
exec $SHELL
rbenv install 1.9.2-p320
rbenv install 1.9.3-p194
rbenv rehash
rbenv global 1.9.2-p320
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 software-properties-common (otherwise 'add-apt-repository' isn't supported) sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs npm
##Step 5 Alt: Install NodeJS via NVM http://bevry.me/learn/node-install
git clone git://github.com/creationix/nvm.git ~/.nvm
printf "\n\n# NVM\nif [ -s ~/.nvm/nvm.sh ]; then\n\tNVM_DIR=~/.nvm\n\tsource ~/.nvm/nvm.sh\nfi" >> ~/.bashrc
NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
nvm ls-remote
##Step 5: Install some other gems You don't need all of these, and most likely, you'll include them in your gemfile for the application you want to use them in, and that's probably the right way, but I usually use these on one app or another that I"m working on, so I'm including them here for reference.
MY COOL GEM LIST heroku taps guard guard-rails guard-test guard-livereload pg capistrano rvm-capistrano devise cancan paperclip formtastic delayed_job rails_admin contact_us qwandry twitter-bootstrap-rails ZURB-foundation annotate pry prawn
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: 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!
sudo apt-add-repository ppa:ubuntu-on-rails/ppa
sudo apt-get update
sudo apt-get install gedit-gmate
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text-2-beta
sudo add-apt-repository ppa:mitya57
sudo apt-get update
sudo apt-get install retext
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 }
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