Skip to content

Latest commit

 

History

History
60 lines (45 loc) · 2.11 KB

Installation.mdown

File metadata and controls

60 lines (45 loc) · 2.11 KB

Installing Ruby and Sinatra

Hi there, so before we can get started with the Sinatra framework, we need to get it to run in the first place, so here is how you get ruby and Sinatra.

Getting Ruby

  • Windows: You're probably in for some pain, consider dual-booting with linux or cygwin. You should also look at rvm (here is a tutorial how to install it in cygwin)

  • Mac OSX: I heard MacRuby was a good choice. You can also use rvm with the GUI for OSX.

  • Linux: I recommend using rvm and installing it as the website recommends. For example Ubuntu still uses the 1.8 version of ruby by default and you can't install personal gems. After installing rvm, run rvm install 1.9.2

Getting Bundler

Bundler manages dependencies to other libraries (called "gems"). You list the gems your application needs in the application root directory in a file with the name Gemfile. The next guy trying to use your application can then simply run bundle install and all dependencies are resolved.

To get bundler, just run gem install bundler in a terminal. If you installed ruby via rvm, that should work, otherwise look at the ruby gems installation page.

Starting a Sinatra project

Make a new directory, in which you make a new file Gemfile, in there, add the repository for the gems first, and then the dependencies:

source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'haml'

Now switch to the directory in a terminal and run bundle install, then wait. Now you can try the Hello World from Sinatra:

# hello.rb
require 'rubygems'
require 'sinatra'

get '/hi' do
  "Hello World!"
end

then run ruby hello.rb. If there are no errors, sinatra is installed just fine. You can exit the server with Ctrl+C.