This is the first post in a series of posts about developing for the web with Ruby on Rails. They’ll be written from the point of view of someone coming from PHP web development. In this post, we’ll take a look at getting set up for developing with Rails.
About a year ago I wrote a book called Jump Start Rails. The idea of if was to get you up and running in just a few days with Rails 4.
This series of posts are an update to that book. I’ll be taking a different approach too. Before dabbling with Rails, I spent a lot of time with PHP. The focus will be based on what it’s like to switch – or use both.
Let’s get started…
Sorry Windows users
I said in the book that I think Rails development on Windows is a bad idea. It’s nothing to do with favouring Apple over Microsoft, it’s simply that you’ll need some Ruby gems that require native extensions. You could be heading for all kinds of pain trying to do that on Windows.
If you insist on using Windows, you do have some options:
- You could use Nitrious.io. I can’t claim to have used it yet, but I have heard very good things about it.
- Ruby installer
- You could use the Rails Installer. I have used this one and it is really great and taking the pain out of the installation process.
- You could install a virtual machine app like VirtualBox and install Ubuntu Linux. More on that in a moment.
Mac Users
There is a bunch of stuff you need/might already have. We’ll deal with the basics first:
- You’ll need XCode which you can get for free from the app store
- I recommend that you install Homebrew. It’s described as the missing package manager for OS X. That description is spot on. You’ll need it to install Postgresql and (potentially) a bunch of other stuff that require native extensions. Get Homebrew installed so that we can use it when the need arises.
- I also recommend that you install Ruby via the excellent RVM. There is also rbenv but RVM is easier to get up and running with. There is an excellent guide to installing RVM on the web site.
Ubuntu Linux Users
You can install RVM too. The sequence to follow looks like this:
- Open Terminal and run the command:
\curl -sSL https://get.rvm.io | bash -s stable
That will install the latest stable version of RVM. - You will also need to run:
source /home/andy/.rvm/scripts/rvm
to make sure that RVM will be operable inside Terminal. - You will also need to open Profile Preferences in Terminal and make sure that the Run command as login shell option is checked. Re-start Terminal to make sure everything is going to work.
- Then, to install Ruby, you can type:
rvm list known
which will show all the versions of Ruby that RVM is aware of. You can then run:rvm install 2.1.2 --default
to install the (currently) latest version of Ruby and set it as the default Ruby on your machine.
If you’ve done everything right, you should be able to run ruby -v
in Terminal and get something like:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
As a response.
Next Steps…
You now have the hard part done. And it wasn’t that bad was it? Let’s face it, there are multiple ways of running PHP these days, so it’s likely you do some configuring for your PHP projects too.
RVM makes installing Rubies easy. Adding Rails is just a matter of getting back on Terminal and doing:
gem install rails
And then watch as the magic happens. You’ll see a lot more about installing gems in later posts.
Postgresql
We’ll be needing a database. Yes, we could use MySQL especially since, as a PHP developer, it’s what you are most familiar with.
However, if we are going to deploy our apps to Heroku, we have to get used to working with PostgresSQL.
Here are some notes about installing:
- Windows – there are installable executables available.
- Mac – you can use Homebrew. It just takes a
brew install postgresql
to get the job done. Follow the instructions after the installation completes regarding starting and stopping Postgres and you’ll be sorted. - Ubuntu Linux – you can install via Terminal with:
sudo apt-get install postgresql postgresql-contrib pgadmin3
. You can set a password for your postgres user with this command:sudo -u postgres psql
. Next, set your new password:ALTER USER postgres PASSWORD 'yournewpassword';
You should be able to use PGAdmin to connect to your database now.
FInally…
That’s the basics covered. There will be more gems to install and configure but we’ll get to those as we need them. Next, we’ll start putting an app together.