I keep making the obviously false assumption that people know how to run Rails apps on a Mac.
If you’re starting from scratch have a look here: http://railsinstaller.org/#osx – I haven’t looked at it, but it looks like it will take a lot of pain away. This post is for people who have an existing app running on an old version.
The following assumes that you have some kind of Ruby installed and some kind of Ruby gems that came with it.
Also, you’ve already got some Rails code, that may be running an old version of everything.
Install XCode if you need to
Start up a terminal and type
If it gives you a command not found error then you need to download XCode from the App Store, fire it up, and then ask it to install the command line utilities. This can take a while, and google is your friend if you don’t know where to find things.
If you already have XCode then you just need to install the command line utilities, which are off on a menu somewhere.
gem install rvm
when it gets to the end of the install it will tell you what to do to your shell environment to run rvm properly. DO IT. 🙂 For reference see https://rvm.io/ If you are unfamiliar with getting things to run in the active shell after altering the shell startup commands, just close the terminal and start a new one, life’s too short.
Install the Ruby you need
In this exercise we want Ruby 1.8.7, so …
rvm install 1.8.7
Eventually it will finish and tell you the version it installed, e.g. ruby-1.8.7-p352
You may encounter some errors, where Apple have kindly set the default C compiler not to be the old GNU ‘C’ compiler but their llvm one. Cut the error message out and paste it into Google, then do what it says.
These instructions might say that it can’t find the command that you put into the environment variable, in which case use whereis cc to tell you where the cc command is.
Any other problems, use the more command or an editor to browse the log file it says
Create a .rvmrc file in your Rails root
Let’s assume the Rails app is called brightstuff. In the root of your Rails app type
If it finds something, have a look and see what it says, for the purposes of this exercise I’m assuming the file isn’t there. Type the command
cat “rvm use ruby-1.8.7-p334@brightstuff” > .rvmrc
Change brightstuff to the name of your app.
This takes you up and then back to the directory you just added the rvmrc to. If you have installed RVM correctly it will ask you if you want to use the .rvmrc. Say yes.
gem install bundler
This will set all the gems up for you in this version of Ruby, in a group named after your app.
Some people don’t use the gemset (which we have named brightstuff) and rely on bundle exec, but I’ve found this to be pretty bomb proof.
You can also install gems independently of the Gemfile used by bundler, I typically install things like powder (see below) like this, because they aren’t needed in any context other than development.
Start the Rails app
As is standard, you can start a development version of the app with:
bundle exec script/server
This will start the app on http://localhost:3000, you can use /etc/hosts and various tools (go look for them) to alias them, and start things on different ports.
I use the pow utility and it’s friend the powder gem to run my apps. http://pow.cx/