dimanche 3 juin 2012

Configuring Ruby on Rails (RoR)

Here are the steps you need to configure your environment to start building Rails web applications:
      • Installing Git
      • Installing Ruby
      • Installing RubyGems
      • Installing Rails

Here are the steps you need to configure your environment to start building Rails web applications.

Installing Git

Rails ecosystem depends tremendously on Git a very powerful version control system. Git must be installed at first as you will see it every time you google any Rails package.
on a Debian-based distribution like Ubuntu, you have to type following instruction to install Git:

$ apt-get install git-core

You may find detailed installation instructions for your platform at the Installing Git section of the book Pro Git.

Installing Ruby

Next thing to do is to install Ruby, for this you need first to install Ruby Version Manager (RVM). RVM primary goal is helping you to install and manage multiple versions of Ruby on the same machine. Following are the steps for installing RVM on Linux, more details can be found in RVM Installation.

You need curl, if you don't have you can installed on Ubuntu by typing:
$ apt-get install curl
Then download RVM
$ curl -L get.rvm.io | bash -s stable
Load RVM
$ source ~/.rvm/scripts/rvm
Check requirements for installing RVM and follow the instructions:
$ rvm requirements
Finally, now you can install Ruby (1.9.3 is latest version)
$ rvm install 1.9.3

For Windows (using Cygwin) check this tutorial.

rbenv is another ruby sandboxing tool lighter and faster than rvm, you can use both in similar way.

Installing RubyGems

RubyGems is a useful package manager for Ruby projects that may save you a lot of time as there are many useful libraries (including Rails) available as Ruby packages, or gems. RubyGems should be automatically installed if you had successfully installed RVM easy once you install Ruby. You may use following command to check its availability:
$ which gem
/Users/mhartl/.rvm/rubies/ruby-1.9.3-p0/bin/gem

Installing Rails

Finally, we are ready for installing Rails framework and star building great web applications. Rails can installed as follows:

$ gem install rails -v 3.2.3

To check Rails installation, run following command to see version number:
$ rails -v
Rails 3.2.3

If you’re running Linux, you might have to install a couple of other packages at this point:

$ sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev # Linux only


You want to configure Ruby on Rails on a virtual machine based on Bodhi Linux 1.4.0 Stable which is a light distro based on Ubuntu 10.04 LTS. I may be useful to use configure_image.sh which is  configuration file that will install most of the things described earlier and other useful gems.
These are the instruction for configuring your vm and testing a sample web applications:

  1. Create a new VM with 256 MB RAM and 4GB HD (VirtualBox > New)
  2. Mount bodhi_1.4.0.iso as a live CD (VirtualBox > Settings > Storage)
  3. Install Bodhi Linux (VirtualBox > *your_VM* > Start)
  4. sudo apt-get update, sudo apt-get upgrade
  5. sudo apt-get install git-core (there's no git on Bodhi preinstalled)
  6. mkdir -p Documents (there's no Documents directory/folder by default)
  7. wget -O configure_image.sh http://pastebin.com/download.php?i=WTXF7g7F
  8. chmod +x configure_image.sh
  9. ./configure_image.sh (setups the necessary development environment ~ 2h!)
  10. cd Documents
  11. mkdir -p hw2_rottenpotatoes_2012 (for my fork of the official repo)*
  12. git clone git://github.com/saasbook/hw2_rottenpotatoes.git
  13. cp -r hw2_rottenpotatoes hw2_rottenpotatoes_2012
  14. cd hw2_rottenpotatoes_2012
  15. bundle install --without production
  16. bundle exec rake db:migrate
  17. rails server
  18. http://0.0.0.0:3000/movies 

Resources

You may have to look for other useful resources:

Aucun commentaire:

Enregistrer un commentaire