by Steven J. Owens (unless otherwise attributed)
The following owes much to various tutorials, howtos, especially the one referenced below, and of course to the ever-helpful community on freenode's #ruby and #RubyOnRails.
I'm following this tutorial to set up Ruby, Ruby Gems and Rails:
http://web2linux.com/installing-rails-3-on-ubuntu-10-04-lucid-lynx/
After that, I'm following the Rails Getting Started Guide:
http://guides.rubyonrails.org/getting_started.html
I'm pretty much following the above tutorials step by step, so I'm not adding a whole lot of value here. On the other hand, I am including full listings of commands and their output. So if you're stumbling through this yourself, you'll be able to see roughly what you should expect, as you go through the tutorials.
As it turns out, the above tutorial misses some of the dependencies, specifically libssl-dev and libxml2-dev, as explained in this tutorial (helpfully pointed out to me by somebody on freenode #rubyonrails).
http://www.ozmox.com/2009/04/18/installing-ruby-on-ubuntu-from-source/
First, I carefully made sure that my ubuntu lucid installation has no other versions of ruby, etc. The first time through, I had installed ruby via apt, and that lead to some weird version conflicts.
I hate going around my configuration management system, but sadly, Ubuntu Lucid's repositories have exactly the wrong versions of Ruby to use with Rails 3.0, according to the Rails 3.0 release notes:
http://edgeguides.rubyonrails.org/30release_notes.html
"Note that Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails 3.0. [...] Ruby 1.9.1 is not usable because it outright segfaults on Rails 3.0, [...]".
And when you look in the repos, you find exactly the wrong versions, 1.8.7 p249, and 1.9.1. Sigh...
puff@redbitter:~/$ sudo aptitude show ruby1.8 Package: ruby1.8 State: not installed Version: 1.8.7.249-2 Priority: optional Section: interpreters Maintainer: Ubuntu DevelopersUncompressed Size: 139k Depends: libc6 (>= 2.3.6-6~), libruby1.8 (>= 1.8.7.249) Suggests: ruby1.8-examples, rdoc1.8, ri1.8 Description: Interpreter of object-oriented scripting language Ruby 1.8 Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in perl). It is simple, straight-forward, and extensible. This package provides version 1.8 series of Ruby. On Debian, Ruby 1.8 is provided as separate packages. You can get full Ruby 1.8 distribution by installing following packages. ruby1.8 ruby1.8-dev ri1.8 rdoc1.8 irb1.8 ruby1.8-elisp ruby1.8-examples libdbm-ruby1.8 libgdbm-ruby1.8 libtcltk-ruby1.8 libopenssl-ruby1.8 libreadline-ruby1.8 Homepage: http://www.ruby-lang.org/ puff@redbitter:~/$ puff@redbitter:~/$ sudo aptitude show ruby1.9 Package: ruby1.9 State: not installed Version: 1.9.0.5-1ubuntu1 Priority: optional Section: universe/interpreters Maintainer: Ubuntu Developers Uncompressed Size: 614k Depends: libc6 (>= 2.3.6-6~), libruby1.9 (>= 1.9.0.5) Suggests: ruby1.9-examples, rdoc1.9, ri1.9, rubygems1.9 Description: Interpreter of object-oriented scripting language Ruby 1.9 Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in perl). It is simple, straight-forward, and extensible. This package provides version 1.9 series of Ruby. NOTE: Ruby 1.9.0 is the development version. Homepage: http://www.ruby-lang.org/ puff@redbitter:~/$
Note: I had planned to use mysql, but I ran into problems with that, so I'm using sqlite3. To do so, I had to use aptitude to install sqlite3 and libsqlite3-dev, and then use gems to install sqlite3-ruby; both steps are shown at that point.
Remember to update apt first!
puff@redbitter:~$ sudo aptitude update Hit http://ppa.launchpad.net lucid Release.gpg Ign http://ppa.launchpad.net/pratikmsinha/ruby192+bindings/ubuntu/ lucid/main Translation-en_US Hit http://us.archive.ubuntu.com lucid Release.gpg Ign http://us.archive.ubuntu.com/ubuntu/ lucid/main Translation-en_US Get:1 http://security.ubuntu.com lucid-security Release.gpg [198B] Ign http://security.ubuntu.com/ubuntu/ lucid-security/main Translation-en_US Hit http://ppa.launchpad.net lucid Release Ign http://us.archive.ubuntu.com/ubuntu/ lucid/restricted Translation-en_US Ign http://us.archive.ubuntu.com/ubuntu/ lucid/universe Translation-en_US Ign http://us.archive.ubuntu.com/ubuntu/ lucid/multiverse Translation-en_US Get:2 http://us.archive.ubuntu.com lucid-updates Release.gpg [198B] Ign http://us.archive.ubuntu.com/ubuntu/ lucid-updates/main Translation-en_US Ign http://us.archive.ubuntu.com/ubuntu/ lucid-updates/restricted Translation-en_US Ign http://us.archive.ubuntu.com/ubuntu/ lucid-updates/universe Translation-en_US Ign http://us.archive.ubuntu.com/ubuntu/ lucid-updates/multiverse Translation-en_US Ign http://security.ubuntu.com/ubuntu/ lucid-security/restricted Translation-en_US Ign http://security.ubuntu.com/ubuntu/ lucid-security/universe Translation-en_US Ign http://security.ubuntu.com/ubuntu/ lucid-security/multiverse Translation-en_US Get:3 http://security.ubuntu.com lucid-security Release [38.5kB] Hit http://us.archive.ubuntu.com lucid Release Get:4 http://us.archive.ubuntu.com lucid-updates Release [44.7kB] Hit http://ppa.launchpad.net lucid/main Packages Hit http://us.archive.ubuntu.com lucid/main Packages Hit http://us.archive.ubuntu.com lucid/restricted Packages Hit http://us.archive.ubuntu.com lucid/main Sources Hit http://us.archive.ubuntu.com lucid/restricted Sources Hit http://us.archive.ubuntu.com lucid/universe Packages Hit http://us.archive.ubuntu.com lucid/universe Sources Get:5 http://security.ubuntu.com lucid-security/main Packages [88.9kB] Hit http://us.archive.ubuntu.com lucid/multiverse Packages Hit http://us.archive.ubuntu.com lucid/multiverse Sources Get:6 http://us.archive.ubuntu.com lucid-updates/main Packages [326kB] Get:7 http://security.ubuntu.com lucid-security/restricted Packages [14B] Get:8 http://security.ubuntu.com lucid-security/main Sources [31.8kB] Get:9 http://security.ubuntu.com lucid-security/restricted Sources [14B] Get:10 http://security.ubuntu.com lucid-security/universe Packages [43.5kB] Get:11 http://us.archive.ubuntu.com lucid-updates/restricted Packages [3,240B] Get:12 http://us.archive.ubuntu.com lucid-updates/main Sources [127kB] Get:13 http://security.ubuntu.com lucid-security/universe Sources [11.4kB] Get:14 http://security.ubuntu.com lucid-security/multiverse Packages [1,994B] Get:15 http://security.ubuntu.com lucid-security/multiverse Sources [656B] Get:16 http://us.archive.ubuntu.com lucid-updates/restricted Sources [1,443B] Get:17 http://us.archive.ubuntu.com lucid-updates/universe Packages [131kB] Get:18 http://us.archive.ubuntu.com lucid-updates/universe Sources [52.6kB] Get:19 http://us.archive.ubuntu.com lucid-updates/multiverse Packages [6,703B] Get:20 http://us.archive.ubuntu.com lucid-updates/multiverse Sources [3,242B] Fetched 913kB in 2s (418kB/s) Reading package lists... DoneCurrent status: 22 updates [+20], 28962 new [+14]. puff@redbitter:~$ puff@redbitter:~$ sudo aptitude install curl git-core build-essential zlib1g-dev libssl-dev libreadline5-dev [sudo] password for puff: Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done The following NEW packages will be installed: build-essential curl dpkg-dev{a} fakeroot{a} git-core libdigest-sha1-perl{a} liberror-perl{a} libncurses5-dev{a} libreadline5{a} libreadline5-dev libssl-dev patch{a} xz-utils{a} 0 packages upgraded, 13 newly installed, 0 to remove and 22 not upgraded. Need to get 10.8MB/10.9MB of archives. After unpacking 28.9MB will be used. Do you want to continue? [Y/n/?] y Writing extended state information... Done Get:1 http://us.archive.ubuntu.com/ubuntu/ lucid/main xz-utils 4.999.9beta+20091116-1 [228kB] Get:2 http://us.archive.ubuntu.com/ubuntu/ lucid/main patch 2.6-2ubuntu1 [123kB] Get:3 http://us.archive.ubuntu.com/ubuntu/ lucid-updates/main dpkg-dev 1.15.5.6ubuntu4.1 [653kB] Get:4 http://us.archive.ubuntu.com/ubuntu/ lucid/main build-essential 11.4build1 [7,278B] Get:5 http://us.archive.ubuntu.com/ubuntu/ lucid/main curl 7.19.7-1ubuntu1 [208kB] Get:6 http://us.archive.ubuntu.com/ubuntu/ lucid/main fakeroot 1.14.4-1ubuntu1 [118kB] Get:7 http://us.archive.ubuntu.com/ubuntu/ lucid/main liberror-perl 0.17-1 [23.8kB] Get:8 http://us.archive.ubuntu.com/ubuntu/ lucid/main libdigest-sha1-perl 2.12-1build1 [26.2kB] Get:9 http://us.archive.ubuntu.com/ubuntu/ lucid/main git-core 1:1.7.0.4-1 [5,623kB] Get:10 http://us.archive.ubuntu.com/ubuntu/ lucid/main libncurses5-dev 5.7+20090803-2ubuntu3 [1,564kB] Get:11 http://us.archive.ubuntu.com/ubuntu/ lucid/main libreadline5-dev 5.2-7build1 [224kB] Get:12 http://us.archive.ubuntu.com/ubuntu/ lucid/main libssl-dev 0.9.8k-7ubuntu8 [2,001kB] Fetched 10.8MB in 37s (287kB/s) debconf: unable to initialize frontend: Dialog debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.) debconf: falling back to frontend: Readline Selecting previously deselected package xz-utils. (Reading database ... 208973 files and directories currently installed.) Unpacking xz-utils (from .../xz-utils4.999.9beta+20091116-1i386.deb) ... Selecting previously deselected package patch. Unpacking patch (from .../patch2.6-2ubuntu1i386.deb) ... Selecting previously deselected package dpkg-dev. Unpacking dpkg-dev (from .../dpkg-dev1.15.5.6ubuntu4.1all.deb) ... Selecting previously deselected package build-essential. Unpacking build-essential (from .../build-essential11.4build1i386.deb) ... Selecting previously deselected package curl. Unpacking curl (from .../curl7.19.7-1ubuntu1i386.deb) ... Selecting previously deselected package fakeroot. Unpacking fakeroot (from .../fakeroot1.14.4-1ubuntu1i386.deb) ... Selecting previously deselected package liberror-perl. Unpacking liberror-perl (from .../liberror-perl0.17-1all.deb) ... Selecting previously deselected package libdigest-sha1-perl. Unpacking libdigest-sha1-perl (from .../libdigest-sha1-perl2.12-1build1i386.deb) ... Selecting previously deselected package git-core. Unpacking git-core (from .../git-core1%3a1.7.0.4-1i386.deb) ... Selecting previously deselected package libncurses5-dev. Unpacking libncurses5-dev (from .../libncurses5-dev5.7+20090803-2ubuntu3i386.deb) ... Selecting previously deselected package libreadline5. Unpacking libreadline5 (from .../libreadline55.2-7build1i386.deb) ... Selecting previously deselected package libreadline5-dev. Unpacking libreadline5-dev (from .../libreadline5-dev5.2-7build1i386.deb) ... Selecting previously deselected package libssl-dev. Unpacking libssl-dev (from .../libssl-dev0.9.8k-7ubuntu8i386.deb) ... Processing triggers for man-db ... debconf: unable to initialize frontend: Dialog debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.) debconf: falling back to frontend: Readline Processing triggers for install-info ... install-info: warning: no info dir entry in `/usr/share/info/xemacs21/emodules.info.gz' Setting up xz-utils (4.999.9beta+20091116-1) ... Setting up patch (2.6-2ubuntu1) ... Setting up dpkg-dev (1.15.5.6ubuntu4.1) ... Setting up build-essential (11.4build1) ... Setting up curl (7.19.7-1ubuntu1) ... Setting up fakeroot (1.14.4-1ubuntu1) ... update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode. Setting up liberror-perl (0.17-1) ... Setting up libdigest-sha1-perl (2.12-1build1) ... Setting up git-core (1:1.7.0.4-1) ... Setting up libncurses5-dev (5.7+20090803-2ubuntu3) ... Setting up libreadline5 (5.2-7build1) ... Setting up libreadline5-dev (5.2-7build1) ... Ignoring install-info called from maintainer script The package libreadline5-dev should be rebuilt with new debhelper to get trigger support Ignoring install-info called from maintainer script The package libreadline5-dev should be rebuilt with new debhelper to get trigger support Setting up libssl-dev (0.9.8k-7ubuntu8) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place vReading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Writing extended state information... Done puff@redbitter:~$
puff@redbitter:~$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 109 328 109 328 0 0 1387 0 --:--:-- --:--:-- --:--:-- 4049 Initialized empty Git repository in /home/puff/.rvm/src/rvm/.git/ remote: Counting objects: 14920, done. remote: Compressing objects: 100% (3921/3921), done. remote: Total 14920 (delta 10044), reused 14395 (delta 9623) Receiving objects: 100% (14920/14920), 2.62 MiB | 160 KiB/s, done. Resolving deltas: 100% (10044/10044), done. RVM: Shell scripts enabling management of multiple ruby environments. RTFM: http://rvm.beginrescueend.com/ HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net) Installing RVM to /home/puff/.rvm/ Correct permissions for base binaries in /home/puff/.rvm/bin... Copying manpages into place.chmod: cannot access `./script/notes': No such file or directory Notes for Linux ( DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.04 DISTRIB_CODENAME=lucid DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS" ) # NOTE: MRI stands for Matz's Ruby Interpreter (1.8.X, 1.9.X), ree stands for Ruby Enterprise Edition and rbx stands for Rubinius. # curl is required. # git is required. # patch is required (for ree, some ruby head's). # If you wish to install rbx and/or any MRI head (eg. 1.9.2-head) then you must install and use rvm 1.8.7 first. # If you wish to have the 'pretty colors' again, set 'export rvm_pretty_print_flag=1' in ~/.rvmrc. dependencies: # For RVM rvm: bash curl git-core # For JRuby (if you wish to use it) you will need: jruby: aptitude install curl sun-java6-bin sun-java6-jre sun-java6-jdk # For MRI & ree (if you wish to use it) you will need (depending on what you are installing): ruby: aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev ruby-head: git subversion autoconf # For IronRuby (if you wish to use it) you will need: ironruby: aptitude install curl mono-2.0-devel You must now complete the install by loading RVM in new shells. 1) Place the folowing line at the end of your shell's loading files (.bashrc or .bash_profile for bash and .zshrc for zsh), after all PATH/variable settings: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. You only need to add this line the first time you install rvm. 2) Ensure that there is no 'return' from inside the ~/.bashrc file, otherwise rvm may be prevented from working properly. This means that if you see something like: '[ -z "$PS1" ] && return' then you change this line to: if [[ -n "$PS1" ]] ; then # ... original content that was below the '&& return' line ... fi # <= be sure to close the if at the end of the .bashrc. # This is a good place to source rvm v v v [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. EOF - This marks the end of the .bashrc file Be absolutely *sure* to REMOVE the '&& return'. If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile. Placing all non-interactive (non login) items in the .bashrc, including the 'source' line above and any environment settings. 3) CLOSE THIS SHELL and open a new one in order to use rvm. WARNING: you have a 'return' statement in your ~/.bashrc This could cause some features of RVM to not work. This means that if you see something like: '[ -z "$PS1" ] && return' then you change this line to: if [[ -n "$PS1" ]] ; then # ... original content that was below the '&& return' line ... fi # <= be sure to close the if at the end of the .bashrc. # This is a good place to source rvm v v v [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. EOF - This marks the end of the .bashrc file Even if you are using zsh you should still adjust the ~/.bashrc If you have any questions about this please visit #rvm on irc.freenode.net. Installation of RVM to /home/puff/.rvm/ is complete. puff, Thank you very much for using RVM! I sincerely hope that RVM helps to make your work both easier and more enjoyable. If you have any questions, issues and/or ideas for improvement please join#rvm on irc.freenode.net and let me know, note you must register (http://bit.ly/5mGjlm) and identify (/msg nickserv) to talk, this prevents spambots from ruining our day. My irc nickname is 'wayneeseguin' and I hang out in #rvm typically ~09:00-17:00EDT and again from ~21:00EDT-~23:00EDT If I do not respond right away, please hang around after asking your question, I will respond as soon as I am back. It is best to talk in #rvm itself as then other users can help out should I be offline. Be sure to get head often as rvm development happens fast, you can do this by running 'rvm update --head' followed by 'rvm reload' or opening a new shell w⦿‿⦿t ~ Wayne puff@redbitter:~$
The default .bashrc under ubuntu lucid has this line near the beginning
# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # ...the rest of your original .bashrc...
This checks for whether .bashrc is being loaded by an interactive terminal or not; if the environment variable PS1 is zero (the -z test, see "man test"), then it's a non-interactive load, so return without loading the rest of .bashrc.
Since we always want to load the rvm stuff, fire up emacs (or your favorite text editor) and turn it inside out; swap -z for -n, and make it an if-block that encloses the rest of .bashrc:
# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # originally: # If not running interactively, don't do anything. # originally: [ -z "$PS1" ] && return # # Changed to support using rvm; instead of returning, invert the # condition and enclose the remainder of .bashrc in an if block. if [ -n "$PS1" ] ; then # ...the rest of your original .bashrc... fi # close of 'if [ -n "$PS1" ]' block
puff@redbitter:~$ rvm notes Notes for Linux ( DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.04 DISTRIB_CODENAME=lucid DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS" ) # NOTE: MRI stands for Matz's Ruby Interpreter (1.8.X, 1.9.X), ree stands for Ruby Enterprise Edition and rbx stands for Rubinius. # curl is required. # git is required. # patch is required (for ree, some ruby head's). # If you wish to install rbx and/or any MRI head (eg. 1.9.2-head) then you must install and use rvm 1.8.7 first. # If you wish to have the 'pretty colors' again, set 'export rvm_pretty_print_flag=1' in ~/.rvmrc. dependencies: # For RVM rvm: bash curl git-core # For JRuby (if you wish to use it) you will need: jruby: aptitude install curl sun-java6-bin sun-java6-jre sun-java6-jdk # For MRI & ree (if you wish to use it) you will need (depending on what you are installing): ruby: aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev ruby-head: git subversion autoconf # For IronRuby (if you wish to use it) you will need: ironruby: aptitude install curl mono-2.0-devel puff@redbitter:~$
This will take anywhere from several minutes to 20 minutes, depending on your network and your machine.
puff@redbitter:~$ rvm install 1.9.2 /home/puff/.rvm/rubies/ruby-1.9.2-p0, this may take a while depending on your cpu(s)... ruby-1.9.2-p0 - #fetching ruby-1.9.2-p0 - #downloading ruby-1.9.2-p0, this may take a while depending on your connection... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 8296k 100 8296k 0 0 16167 0 0:08:45 0:08:45 --:--:-- 20528 ruby-1.9.2-p0 - #extracting ruby-1.9.2-p0 to /home/puff/.rvm/src/ruby-1.9.2-p0 ruby-1.9.2-p0 - #extracted to /home/puff/.rvm/src/ruby-1.9.2-p0 ruby-1.9.2-p0 - #configuring ruby-1.9.2-p0 - #compiling ruby-1.9.2-p0 - #installing ruby-1.9.2-p0 - updating #rubygems for /home/puff/.rvm/gems/ruby-1.9.2-p0@global ruby-1.9.2-p0 - updating #rubygems for /home/puff/.rvm/gems/ruby-1.9.2-p0 ruby-1.9.2-p0 - adjusting #shebangs for (gem). ruby-1.9.2-p0 - #importing default gemsets (/home/puff/.rvm/gemsets/) Install of ruby-1.9.2-p0 - #complete puff@redbitter:~$
Now set rvm to default the version to ruby-1.9.2. If you're starting from scratch here, 1.9.2 is probably the only version you have, but what the hey.
puff@redbitter:~$ rvm --default ruby-1.9.2 puff@redbitter:~$ ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux] puff@redbitter:~$
Now use gem to install rails 3:
puff@redbitter:~/usardell$ gem install railsSuccessfully installed activesupport-3.0.0 Successfully installed builder-2.1.2 Successfully installed i18n-0.4.1 Successfully installed activemodel-3.0.0 Successfully installed rack-1.2.1 Successfully installed rack-test-0.5.6 Successfully installed rack-mount-0.6.13 Successfully installed tzinfo-0.3.23 Successfully installed abstract-1.0.0 Successfully installed erubis-2.6.6 Successfully installed actionpack-3.0.0 Successfully installed arel-1.0.1 Successfully installed activerecord-3.0.0 Successfully installed activeresource-3.0.0 Successfully installed mime-types-1.16 Successfully installed polyglot-0.3.1 Successfully installed treetop-1.4.8 Successfully installed mail-2.2.7 Successfully installed actionmailer-3.0.0 Successfully installed thor-0.14.3 Successfully installed railties-3.0.0 Successfully installed rails-3.0.0 22 gems installed Installing ri documentation for activesupport-3.0.0... Installing ri documentation for builder-2.1.2... Installing ri documentation for i18n-0.4.1... Installing ri documentation for activemodel-3.0.0... Installing ri documentation for rack-1.2.1... Installing ri documentation for rack-test-0.5.6... Installing ri documentation for rack-mount-0.6.13... Installing ri documentation for tzinfo-0.3.23... Installing ri documentation for abstract-1.0.0... Installing ri documentation for erubis-2.6.6... Installing ri documentation for actionpack-3.0.0... Installing ri documentation for arel-1.0.1... Installing ri documentation for activerecord-3.0.0... Installing ri documentation for activeresource-3.0.0... Installing ri documentation for mime-types-1.16... Installing ri documentation for polyglot-0.3.1... Installing ri documentation for treetop-1.4.8... Installing ri documentation for mail-2.2.7... Installing ri documentation for actionmailer-3.0.0... Installing ri documentation for thor-0.14.3... Installing ri documentation for railties-3.0.0... Installing ri documentation for rails-3.0.0... Installing RDoc documentation for activesupport-3.0.0... Installing RDoc documentation for builder-2.1.2... Installing RDoc documentation for i18n-0.4.1... Installing RDoc documentation for activemodel-3.0.0... Installing RDoc documentation for rack-1.2.1... Installing RDoc documentation for rack-test-0.5.6... Installing RDoc documentation for rack-mount-0.6.13... Installing RDoc documentation for tzinfo-0.3.23... Installing RDoc documentation for abstract-1.0.0... Installing RDoc documentation for erubis-2.6.6... Installing RDoc documentation for actionpack-3.0.0... Installing RDoc documentation for arel-1.0.1... Installing RDoc documentation for activerecord-3.0.0... Installing RDoc documentation for activeresource-3.0.0... Installing RDoc documentation for mime-types-1.16... Installing RDoc documentation for polyglot-0.3.1... Installing RDoc documentation for treetop-1.4.8... Installing RDoc documentation for mail-2.2.7... Installing RDoc documentation for actionmailer-3.0.0... Installing RDoc documentation for thor-0.14.3... Installing RDoc documentation for railties-3.0.0... Installing RDoc documentation for rails-3.0.0... Successfully installed rails-3.0.0 puff@redbitter:~$
puff@redbitter:~$ rails new blog [1m[32m create[0m [1m[32m create[0m README [1m[32m create[0m Rakefile [1m[32m create[0m config.ru [1m[32m create[0m .gitignore [1m[32m create[0m Gemfile [1m[32m create[0m app [1m[32m create[0m app/controllers/application_controller.rb [1m[32m create[0m app/views/layouts/application.html.erb [1m[32m create[0m app/helpers/application_helper.rb [1m[32m create[0m app/models [1m[32m create[0m app/mailers [1m[32m create[0m config [1m[32m create[0m config/routes.rb [1m[32m create[0m config/application.rb [1m[32m create[0m config/environment.rb [1m[32m create[0m config/environments [1m[32m create[0m config/environments/development.rb [1m[32m create[0m config/environments/test.rb [1m[32m create[0m config/environments/production.rb [1m[32m create[0m config/initializers [1m[32m create[0m config/initializers/inflections.rb [1m[32m create[0m config/initializers/session_store.rb [1m[32m create[0m config/initializers/secret_token.rb [1m[32m create[0m config/initializers/mime_types.rb [1m[32m create[0m config/initializers/backtrace_silencers.rb [1m[32m create[0m config/locales [1m[32m create[0m config/locales/en.yml [1m[32m create[0m config/boot.rb [1m[32m create[0m config/database.yml [1m[32m create[0m db [1m[32m create[0m db/seeds.rb [1m[32m create[0m doc [1m[32m create[0m doc/README_FOR_APP [1m[32m create[0m lib [1m[32m create[0m lib/tasks [1m[32m create[0m lib/tasks/.gitkeep [1m[32m create[0m log [1m[32m create[0m log/server.log [1m[32m create[0m log/production.log [1m[32m create[0m log/development.log [1m[32m create[0m log/test.log [1m[32m create[0m public [1m[32m create[0m public/404.html [1m[32m create[0m public/index.html [1m[32m create[0m public/favicon.ico [1m[32m create[0m public/robots.txt [1m[32m create[0m public/500.html [1m[32m create[0m public/422.html [1m[32m create[0m public/images [1m[32m create[0m public/images/rails.png [1m[32m create[0m public/stylesheets [1m[32m create[0m public/stylesheets/.gitkeep [1m[32m create[0m public/javascripts [1m[32m create[0m public/javascripts/controls.js [1m[32m create[0m public/javascripts/dragdrop.js [1m[32m create[0m public/javascripts/effects.js [1m[32m create[0m public/javascripts/application.js [1m[32m create[0m public/javascripts/rails.js [1m[32m create[0m public/javascripts/prototype.js [1m[32m create[0m script [1m[32m create[0m script/rails [1m[32m create[0m test [1m[32m create[0m test/performance/browsing_test.rb [1m[32m create[0m test/test_helper.rb [1m[32m create[0m test/functional [1m[32m create[0m test/fixtures [1m[32m create[0m test/unit [1m[32m create[0m test/integration [1m[32m create[0m tmp [1m[32m create[0m tmp/sessions [1m[32m create[0m tmp/sockets [1m[32m create[0m tmp/cache [1m[32m create[0m tmp/pids [1m[32m create[0m vendor/plugins [1m[32m create[0m vendor/plugins/.gitkeep puff@redbitter:~$
As mentioned above, I had planned to use mysql (since I know it better), but ran into problems, so I'm using sqlite3, which the default database.yml is already configured to use.
Really, I should have lumped some of this up at the beginning where I was "installing prerequisites", but hindsight is 20/20...
First, install sqlite3 and libsqlite3-dev:
puff@redbitter:~/blog$ sudo aptitude install sqlite3 libsqlite3-dev Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done The following NEW packages will be installed: libsqlite3-dev sqlite3 0 packages upgraded, 2 newly installed, 0 to remove and 26 not upgraded. Need to get 397kB of archives. After unpacking 1,044kB will be used. Writing extended state information... Done Get:1 http://us.archive.ubuntu.com/ubuntu/ lucid/main libsqlite3-dev 3.6.22-1 [371kB] Get:2 http://us.archive.ubuntu.com/ubuntu/ lucid/main sqlite3 3.6.22-1 [26.5kB] Fetched 397kB in 3s (102kB/s) debconf: unable to initialize frontend: Dialog debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.) debconf: falling back to frontend: Readline Selecting previously deselected package libsqlite3-dev. (Reading database ... 212495 files and directories currently installed.) Unpacking libsqlite3-dev (from .../libsqlite3-dev_3.6.22-1_i386.deb) ... Selecting previously deselected package sqlite3. Unpacking sqlite3 (from .../sqlite3_3.6.22-1_i386.deb) ... Processing triggers for man-db ... debconf: unable to initialize frontend: Dialog debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.) debconf: falling back to frontend: Readline Setting up libsqlite3-dev (3.6.22-1) ... Setting up sqlite3 (3.6.22-1) ... Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Writing extended state information... Done puff@redbitter:~/blog$
Now gem install sqlite3-ruby:
puff@redbitter:~/blog$ gem install sqlite3-ruby Building native extensions. This could take a while... Successfully installed sqlite3-ruby-1.3.1 1 gem installed Installing ri documentation for sqlite3-ruby-1.3.1... Installing RDoc documentation for sqlite3-ruby-1.3.1... puff@redbitter:~/blog$
And finally do bundle install:
puff@redbitter:~/blog$ bundle install Fetching source index for http://rubygems.org/ Using rake (0.8.7) Using abstract (1.0.0) Using activesupport (3.0.0) Using builder (2.1.2) Using i18n (0.4.1) Using activemodel (3.0.0) Using erubis (2.6.6) Using rack (1.2.1) Using rack-mount (0.6.13) Using rack-test (0.5.4) Using tzinfo (0.3.23) Using actionpack (3.0.0) Using mime-types (1.16) Using polyglot (0.3.1) Using treetop (1.4.8) Using mail (2.2.6.1) Using actionmailer (3.0.0) Using arel (1.0.1) Using activerecord (3.0.0) Using activeresource (3.0.0) Using bundler (1.0.0) Using thor (0.14.1) Using railties (3.0.0) Using rails (3.0.0) Using sqlite3-ruby (1.3.1) [32mYour bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.[0m [32m Your bundle was installed to `/home/puff/.rvm/gems/ruby-1.9.2-p0`[0m puff@redbitter:~/blog$
Now create the database:
puff@redbitter:~/blog$ rake db:create (in /home/puff/blog) db/test.sqlite3 already exists db/development.sqlite3 already exists puff@redbitter:~/blog$
Interesting, it looks like the database structure was already created:
puff@redbitter:~/blog$ ls -l db/ total 4 -rw-r--r-- 1 puff puff 0 2010-10-09 23:40 development.sqlite3 -rw-r--r-- 1 puff puff 353 2010-10-09 23:33 seeds.rb -rw-r--r-- 1 puff puff 0 2010-10-09 23:40 test.sqlite3 puff@redbitter:~/blog$
Start up the server:
puff@redbitter:~/blog$ rails server => Booting WEBrick => Rails 3.0.0 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2010-10-10 00:01:38] INFO WEBrick 1.3.1 [2010-10-10 00:01:38] INFO ruby 1.9.2 (2010-08-18) [i686-linux] [2010-10-10 00:01:38] INFO WEBrick::HTTPServer#start: pid=4117 port=3000
Point your browser at http://localhost:3000 and you should see the "Welcome aboard" page:
Welcome aboard You’re riding Ruby on Rails! About your application’s environment Getting started Here’s how to get rolling: 1. Use rails generate to create your models and controllers To see all available options, run it without parameters. 2. Set up a default route and remove or rename this file Routes are set up in config/routes.rb. 3. Create your database Run rake db:migrate to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.
Okay, time to set up a controller, view and route for your "Hello Rails" exercise. First the controller:
puff@redbitter:~/blog$ rails generate controller home index create app/controllers/home_controller.rb route get "home/index" invoke erb create app/views/home create app/views/home/index.html.erb invoke test_unit create test/functional/home_controller_test.rb invoke helper create app/helpers/home_helper.rb invoke test_unit create test/unit/helpers/home_helper_test.rb puff@redbitter:~/blog$
Now fire up your favorite editor to edit the view file created by that rails controller command above:
puff@redbitter:~/blog$ emacs app/views/home/index.html.erb ---------------------------------------------------------------------- <h1>Home#index</h1> <p>Find me in app/views/home/index.html.erb</p> ----------------------------------------------------------------------
Change it to this:
---------------------------------------------------------------------- Hello Rails ----------------------------------------------------------------------
Save the file and exit your editor.
So now we have the controller, and we've edited the view, so we need to delete the default index.html and edit the routes.rb file.
I'm guessing that Rails ERB acts much like apache cgi and php, in that the presence of an index.html overrides an index.cgi or index.php, e.g. the web server won't bother to invoke the other files as long as the index.html is there.
puff@redbitter:~/blog$ rm public/index.html puff@redbitter:~/blog$
Edit config/routes.rb:
puff@redbitter:~/blog$ emacs config/routes.rb ---------------------------------------------------------------------- Blog::Application.routes.draw do get "home/index" # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get 'recent', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. # root :to => "welcome#index" # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id(.:format)))' end ----------------------------------------------------------------------
Uncomment the "root :to" line and edit it to use home#index
puff@redbitter:~/blog$ emacs ./config/routes.rb ---------------------------------------------------------------------- Blog::Application.routes.draw do get "home/index" # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource route with options: # resources :products do # member do # get 'short' # post 'toggle' # end # # collection do # get 'sold' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource route with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get 'recent', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. root :to => "home#index" # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id(.:format)))' end ----------------------------------------------------------------------
Save and close the file, then load up http://localhost:3000 again.
Hm, and look at the pretty error message:
LoadError in HomeController#indexno such file to load -- openssl
Rails.root: /home/puff/blog Application Trace | Framework Trace | Full Trace
This error occurred while loading the following files: openssl
Request
Parameters:
None
Show session dump
Show env dump
Response
Headers:
None
Okay, it looks like we missed some dependencies up at the top.
One of the nice folks on freenode #rubyonrails pointed me at the ozmox tutorial (see the link in the intro). As it turns out, I'm missing two package dependencies, libssl-dev and libxml2-dev. The answer is to install them, and then rebuild ruby.
puff@redbitter:~/blog$ sudo aptitude install build-essential zlib1g zlib1g-dev libxml2 libxml2-dev libssl-dev [sudo] password for puff: Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done The following NEW packages will be installed: libssl-dev libxml2-dev 0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 2,762kB of archives. After unpacking 8,024kB will be used. Writing extended state information... Done Get:1 http://us.archive.ubuntu.com/ubuntu/ lucid-updates/main libssl-dev 0.9.8k-7ubuntu8.3 [2,011kB] Get:2 http://us.archive.ubuntu.com/ubuntu/ lucid/main libxml2-dev 2.7.6.dfsg-1ubuntu1 [751kB] Fetched 2,762kB in 13s (203kB/s) debconf: unable to initialize frontend: Dialog debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.) debconf: falling back to frontend: Readline Selecting previously deselected package libssl-dev. (Reading database ... 198613 files and directories currently installed.) Unpacking libssl-dev (from .../libssl-dev_0.9.8k-7ubuntu8.3_i386.deb) ... Selecting previously deselected package libxml2-dev. Unpacking libxml2-dev (from .../libxml2-dev_2.7.6.dfsg-1ubuntu1_i386.deb) ... Processing triggers for man-db ... debconf: unable to initialize frontend: Dialog debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.) debconf: falling back to frontend: Readline Setting up libssl-dev (0.9.8k-7ubuntu8.3) ... Setting up libxml2-dev (2.7.6.dfsg-1ubuntu1) ... Reading package lists... Done Building dependency tree Reading state information... Done Reading extended state information Initializing package states... Done Writing extended state information... Donepuff@redbitter:~/blog$
Now delete your existing .rvm and start from scratch:
puff@redbitter:~$ rm -rf .rvm/ puff@redbitter:~$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 113 683 113 683 0 0 2861 0 --:--:-- --:--:-- --:--:-- 7941 Initialized empty Git repository in /home/puff/.rvm/src/rvm/.git/ remote: Counting objects: 15334, done. remote: Compressing objects: 100% (4176/4176), done. remote: Total 15334 (delta 10350), reused 14583 (delta 9773) Receiving objects: 100% (15334/15334), 2.67 MiB | 124 KiB/s, done. Resolving deltas: 100% (10350/10350), done. RVM: Shell scripts enabling management of multiple ruby environments. RTFM: http://rvm.beginrescueend.com/ HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net) Installing RVM to /home/puff/.rvm/ Correct permissions for base binaries in /home/puff/.rvm/bin... Copying manpages into place. Notes for Linux ( DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.04 DISTRIB_CODENAME=lucid DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS" ) # NOTE: MRI stands for Matz's Ruby Interpreter (1.8.X, 1.9.X), ree stands for Ruby Enterprise Edition and rbx stands for Rubinius. # curl is required. # git is required. # patch is required (for ree, some ruby head's). # If you wish to install rbx and/or any MRI head (eg. 1.9.2-head) then you must install and use rvm 1.8.7 first. # If you wish to have the 'pretty colors' again, set 'export rvm_pretty_print_flag=1' in ~/.rvmrc. dependencies: # For RVM rvm: bash curl git-core # For JRuby (if you wish to use it) you will need: jruby: aptitude install curl sun-java6-bin sun-java6-jre sun-java6-jdk # For MRI & ree (if you wish to use it) you will need (depending on what you are installing): ruby: aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev ruby-head: git subversion autoconf # For IronRuby (if you wish to use it) you will need: ironruby: aptitude install curl mono-2.0-devel You must now complete the install by loading RVM in new shells. 1) Place the folowing line at the end of your shell's loading files (.bashrc or .bash_profile for bash and .zshrc for zsh), after all PATH/variable settings: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. You only need to add this line the first time you install rvm. 2) Ensure that there is no 'return' from inside the ~/.bashrc file, otherwise rvm may be prevented from working properly.This means that if you see something like: '[ -z "$PS1" ] && return' then you change this line to: if [[ -n "$PS1" ]] ; then # ... original content that was below the '&& return' line ... fi # <= be sure to close the if at the end of the .bashrc. # This is a good place to source rvm v v v [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. EOF - This marks the end of the .bashrc file Be absolutely sure to REMOVE the '&& return'. If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile. Placing all non-interactive (non login) items in the .bashrc, including the 'source' line above and any environment settings. 3) CLOSE THIS SHELL and open a new one in order to use rvm. WARNING: you have a 'return' statement in your ~/.bashrc This could cause some features of RVM to not work. This means that if you see something like: '[ -z "$PS1" ] && return' then you change this line to: if [[ -n "$PS1" ]] ; then # ... original content that was below the '&& return' line ... fi # <= be sure to close the if at the end of the .bashrc. # This is a good place to source rvm v v v [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. EOF - This marks the end of the .bashrc file Even if you are using zsh you should still adjust the ~/.bashrc If you have any questions about this please visit #rvm on irc.freenode.net. Installation of RVM to /home/puff/.rvm/ is complete. puff, Thank you very much for using RVM! I sincerely hope that RVM helps to make your work both easier and more enjoyable. If you have any questions, issues and/or ideas for improvement please join#rvm on irc.freenode.net and let me know, note you must register (http://bit.ly/5mGjlm) and identify (/msg nickserv
) to talk, this prevents spambots from ruining our day. My irc nickname is 'wayneeseguin' and I hang out in #rvm typically ~09:00-17:00EDT and again from ~21:00EDT-~23:00EDT If I do not respond right away, please hang around after asking your question, I will respond as soon as I am back. It is best to talk in #rvm itself as then other users can help out should I be offline. Be sure to get head often as rvm development happens fast, you can do this by running 'rvm update --head' followed by 'rvm reload' or opening a new shell w⦿‿⦿t ~ Wayne
Okay, now use rvm to install ruby 1.9.2 again:
puff@redbitter:~$ rvm install 1.9.2 /home/puff/.rvm/rubies/ruby-1.9.2-p0, this may take a while depending on your cpu(s)... ruby-1.9.2-p0 - #fetching ruby-1.9.2-p0 - #downloading ruby-1.9.2-p0, this may take a while depending on your connection... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 8296k 100 8296k 0 0 51184 0 0:02:45 0:02:45 --:--:-- 31947 ruby-1.9.2-p0 - #extracting ruby-1.9.2-p0 to /home/puff/.rvm/src/ruby-1.9.2-p0 ruby-1.9.2-p0 - #extracted to /home/puff/.rvm/src/ruby-1.9.2-p0 ruby-1.9.2-p0 - #configuring ruby-1.9.2-p0 - #compiling ruby-1.9.2-p0 - #installing ruby-1.9.2-p0 - updating #rubygems for /home/puff/.rvm/gems/ruby-1.9.2-p0@global ruby-1.9.2-p0 - updating #rubygems for /home/puff/.rvm/gems/ruby-1.9.2-p0 ruby-1.9.2-p0 - adjusting #shebangs for (gem). ruby-1.9.2-p0 - #importing default gemsets (/home/puff/.rvm/gemsets/) Install of ruby-1.9.2-p0 - #complete bash: declare: write error: Broken pipe puff@redbitter:~$
Now what's this "bash: declare: write error: Broken pipe" stuff about?
I tried to set the default ruby version:
puff@redbitter:~$ rvm --default 1.9.2 bash: declare: write error: Broken pipe puff@redbitter:~$
I'm not sure, but I exited this shell and started a new shell, and this error went away, so it probably had something to do with rvm and environment variables.
Next use gem to install rails 3, this turned out to be identical to the example in step 5, so I'm not going to include it here.
Next, repeat steps 6 ("rails new blog"), 7 (customize your database.yml) and 8 (bundle install):
Here's the commands, without the output:
puff@redbitter:~$ gem install rails puff@redbitter:~$ rails new blog puff@redbitter:~$ cd blog puff@redbitter:~/blog$ bundle install
...and start the server:
puff@redbitter:~/blog$ rails server
Point your browser at http://localhost:3000 to test your installation.
Redo the "Hello Rails" steps:
puff@redbitter:~/blog$ rails generate controller home index puff@redbitter:~/blog$ emacs ./app/views/home/index.html.erb puff@redbitter:~/blog$ rm ./public/index.html puff@redbitter:~/blog$ emacs ./config/routes.rb
In routes.rb, change the line that looks like this:
# root :to => "welcome#index"
To this:
root :to => "home#index"