I’m running Mac OSX 10.6.4 and Ruby on Rails is already installed natively on the machine. I believe most if not all versions of the Mac OS include Rails. To locate it all you have to do is launch the Terminal which can be found in Applications > Utilities > Terminal using a finder window.
Just launch Terminal and type in rails to confirm that the app exists and get a path printed to where it is. For me the path is /usr/bin/rails and a whole list of Options is also printed out. Now, you don’t actually have to launch rails by navigating that path, you can use it straight from the Terminal with the following commands.
- pwd (print working directory)
- cd (change directory)
- ls (list) ls -F (shows type)
- mkdir (make directory, folder)
- rm (remove)
- rmdir “name of directory” (removes dir)
- which “command”
- man “command” (print out manual page)
- cat “file” (prints out a file)
- more “file” (stops it page by page)
- rm -rf “name” (remove directory)
- Ctrl+c breaks out
I started out by typing pwd to print the directory I was in (which turned out to be “Home$” now in your case this might be your name since that is the default that Mac OSX usually names it when you setup your computer. My next command was mkdir Rails which created a new folder called /Rails in my Home directory. I then typed cd Rails to get into the new directory and then typed rails test (test is the name of the new folder that rails will create in the folder Rails).
At this point a whole bunch of lines will print as rails installs all of the components for a new site in the /test folder. That’s exactly what is shown in the image just below.
Next you can use the change directory command “cd” to get into the test folder you just created with the rails function. Type cd test and then confirm your location by typing pwd. Next you can tell ruby to create a scaffold which actually creates strings and CRUD (create read update and delete) functions. Here is an example: ruby script/generate scaffold test name:string address:text email:string price:decimal
That’s it, just a basic intro to Ruby here but hopefully it helps anyone who is on a Mac get started or remember some of the basic commands. I recommend checking out the book Head First Rails by David Griffiths for more information.
One last thing worth mentioning, if you launch the server by typing ruby script/server and then try to generate your scaffold or setup the database it won’t work. You have to stop the server first by pressing control+c to break out. You can always start the server again later with the ruby script/server command.