Created
June 22, 2012 06:20
-
-
Save tagrudev/2970755 to your computer and use it in GitHub Desktop.
Installing working ruby + rails env on 12.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Step 2: Add required applications. | |
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion ruby ncurses-term mercurial ruby-dev exuberant-ctags libnotify-bin curl autoconf make automake ssh openjdk-6-jdk git-core git-doc imagemagick postgresql-contrib libpq-dev postgresql pgadmin3 vim vim-rails vim-gnome nodejs | |
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 | |
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 | |
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 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 simple_form delayed_job rails_admin contact_us qwandry twitter-bootstrap-rails ZURB-foundation annotate pry prawn | |
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' | |
view rawgistfile1.txtThis Gist brought to you by GitHub. | |
### 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' | |
view rawgistfile1.txtThis Gist brought to you by GitHub. | |
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 | |
} | |
view rawrubyplusplus 20-05-2012 Rails Dev Setup Extras - ScriptsThis Gist brought to you by GitHub. | |
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 | |
} | |
view rawrubyplusplus 20-05-2012 Rails Dev Setup Extras - ScriptsThis Gist brought to you by GitHub. | |
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 | |
Email ThisBlogThis!Share to TwitterShare to Facebook | |
Labels: 12.04, how-to, precise pangolin, ruby on rails, ubuntu | |
10 comments: | |
UnknownJune 20, 2012 | |
As an alternative to rvm, I've been using the packages from brightbox. It works really well. See blog post at http://blog.brightbox.co.uk/posts/next-generation-ruby-packages-for-ubuntu | |
ReplyDelete | |
Replies | |
Eric ProctorJune 20, 2012 | |
I've never looked into this before so thanks for the tip. What benefits does this have over rvm? I'm going to read over the post now, I'm just curious if I could get a cheat sheet! :) | |
Delete | |
Reply | |
UnknownJune 21, 2012 | |
BrightBox packages are great! Why: | |
- pre-compiled - if you are using for example Chef, the install time will be much shorer | |
- native OS integration - everything is on the right place, easy to switch (ruby-switch utility, using alternatives) | |
- support - packages are pretty much up-to-date with all recent patches etc. | |
- Easy to use - RVM is based on some cd command hacks, so there is always some hassle, when using the with sudo, ather accounts, scripts etc. | |
ReplyDelete | |
faitswulffJune 21, 2012 | |
Thank you for this! You are my hero. | |
ReplyDelete | |
Replies | |
Eric ProctorJune 21, 2012 | |
I just hope it works out for you as well as it has worked out for me! | |
Delete | |
Reply | |
Soluções em Software e TIJune 21, 2012 | |
Good work! | |
Thanks | |
ReplyDelete | |
Replies | |
Eric ProctorJune 21, 2012 | |
Thanks! | |
Delete | |
Reply | |
Eric ProctorJune 21, 2012 | |
Hey, to anyone reading this, I just made an important update that I missed. In the initial sudo apt-get install command where I installed a bunch of pre-requisites, I added 'nodejs' to the end of that. Definitely good to have and avoid the "Could not find a javascript runtime error." | |
ReplyDelete | |
Kevin McCaugheyJune 21, 2012 | |
Redcar editor is a great setup for Ubuntu. I have it running on 12.04. Doing a "redcar ." in your project has the same effect as it would in textmate and it looks great. | |
ReplyDelete | |
Replies | |
Eric ProctorJune 21, 2012 | |
Man, to be completely honest, I haven't looked at redcar in a long time. I will add it tonight and give it a shot. For anyone who doesn't know, you can just open a terminal and type: | |
gem install redcar | |
Delete | |
Reply | |
Load more... | |
The authors at rubyplusplus encourage open discussion about ruby, ruby on rails, programming in general, any post that appears on this site or any other interesting topics related to technology. Please post responsibly. | |
Links to this post | |
Ubuntu 12.04 Ruby on Rails Development Environment : RubyFlow | |
I know I'm late to the party, but I just couldn't find a guide that documented a rails setup the way that I needed it to, so I just posted an updated Ruby on Rails setup guide for Ubuntu 12.04 LTS, Precise Pangolin. The guide includes the basic ... | |
Posted by at June 20, 2012 | |
Create a Link |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment