Mijndert's Weblog

3 notes

[Mac] Get started with Ruby on Rails

This is part 1 in a series I’m going to attempt.

There’s more ways to install Ruby on Rails along with Apache and MySQL on Mac OS. You could either use the Bitnami Rubystack or compile a lot from source using MacPorts. I’m going for the latter due to it giving me more flexibility. 

Requirements

First off you need to install Xcode which includes the necessary libraries and compilers to use MacPorts.

Enable Apache

Mac OS includes Apache by default. You can enable it by going to System Preferences > Sharing > Web Sharing.

Bonus: enable php

To enable PHP you need to edit a file.

vim /etc/apache2/httpd.conf

Search for ‘php’ and uncomment the following.

LoadModule php5_module        libexec/apache2/libphp5.so

Now restart Apache in the Sharing Preference Pane and test PHP by putting a file called index.php in your webroot.

<?php phpinfo(); ?>

Install MySQL, Subversion and Ruby using MacPorts

I’m going to asume you already installed MacPorts. If not, read their documentation.

There’s really just one commando that should get you up and running with MySQL, Subversion and Ruby on no-time.

sudo port install mysql5-server ruby rb-mysql rb-rubygems rb-termios subversion +tools

This command will pull the source, compile everything and give you a few pointers on how to proceed. These are the additional commands to setup MySQL so that it starts automatically during boot.

sudo -u _mysql mysql_install_db5

sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock

sudo port load mysql5-server

Install Ruby gems

All you need to do now is install a few Ruby gems. There’s a bunch of Gems I install by default. I recommend you lookup the documentation of each gem to determine whether you need it or not. Gems you ‘Rails’ and ‘Mysql’ you’ll probably need, though.

sudo gem install rails rake capistrano mysql haml ruby-debug will_paginate sqlite3-ruby

Again gem will figure out all the dependencies for you. In order to get the latest and greatest pre-release of Rails, enter the following command in your favorite Terminal app.

sudo gem install rails —pre

Starting off with Ruby on Rails

To generate your first Ruby on Rails application you just need to ‘cd’ into your Sites directory and create the Rails structure.

rails new myapp

Test that everything’s working by invoking the WEBrick server.

Rails 2.x

cd myapp; ./script/server

Rails 3.x

cd myapp; ./script/rails server

Both will give you a working web server on http://0.0.0.0:3000. You can now proceed with one of the excellent tutorials on how to build you very first Ruby on Rails application.

Filed under ruby on rails mac ruby rails development

  1. zachrose reblogged this from joshtrucks and added:
    Hey Josh! Yeah, you need Xcode. I can send you a disk if you need it. Then get MacPorts. Other than that, try opening...
  2. joshtrucks reblogged this from mijndertstuij
  3. mijndertstuij posted this