Skip to content

Instantly share code, notes, and snippets.

@pwightman
Created September 18, 2012 04:11
Show Gist options
  • Save pwightman/3741205 to your computer and use it in GitHub Desktop.
Save pwightman/3741205 to your computer and use it in GitHub Desktop.
Installing RVM and Rails

Install Ubuntu on Windows

Mac OSX/Ubuntu users can skip this section. If you're running Windows, follow these instructions to install Ubuntu inside a virtual machine.

  • Download and install VirtualBox from here
  • Download this Ubuntu ISO file (Note that this is 64-bit, if you don't have a 64-bit machine then you'll want to do the 32-bit version
  • Start up VirtualBox and create a new virtual machine for Ubuntu (just follow default options on each screen if you aren't sure what to do. I recommend doing a 40GB hard drive. It won't actually consume that much, it allocates space as it needs it.)
  • Once the virtual machine is created, click on the VM you just created in the list of VMs and click the Settings button
  • In the Storage section, add an IDE controller that points to the .iso file you just downloaded
  • Start up the VM and follow the Ubuntu installation instructions, following default options when you aren't sure.

You should be good to go at that point, ready to install Ruby and Rails.

Install RVM

RVM is a program that manages your ruby installations and makes it much easier to work with Rails projects.

If you're installing it on Mac OSX, just make sure you've installed Xcode, and then the command-line tools by going to Xcode -> Preferences, Downloads tab, then install Command-line tools. The rest of these commands apply to Ubuntu and OSX, except where specified.

Run this command (Ubuntu Only):

	sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config

type Y when prompted.

Then this one:

curl -L https://get.rvm.io | bash -s stable --ruby

It will download some stuff, then tell you what it's going to do. Press q to continue. It will install yaml and ruby.

Close your terminal window and follow these directions if you're using Ubuntu.

Reopen your terminal windows. Run this:

rvm

and it should print out a bunch of info. If it says "command not found" then something went wrong.

now do:

rvm 1.9.3 --default

This will make the version of ruby you just installed the default version when your terminal starts up. It should not print anything out and you'll know it worked correctly. Now:

gem install rails --no-rdoc --no-ri

This will install Ruby on Rails. It will take a minute, be patient. The --no-rdoc and --no-ri commands tell it not to install the documentation, it takes longer than the source code!

Now you have the basic rails install.

Creating Projects

I follow this same pattern everytime I create a new Rails project.

  1. Decide where you want the project to go (maybe create a rails folder in your home folder)
  2. run rails new <app_name>, where <app_name> is whatever your rails app is called. It will print out a bunch of stuff, and when it gets to bundle install it will hang for a bit. Feel free to kill it with ctrl+c or just wait.
  3. Enter your app directory with cd <app_name>
  4. If you're running linux, you'll want to open the Gemfile which is in the root directory of your project and add the line: gem "therubyracer" somewhere in there, it doesn't matter where.
  5. Using your favorite text editor, create a file in the root directory of your project called .rvmrc and put this inside: rvm 1.9.3@<app_name> --create where <app_name> is the name of your app.
  6. Use cd .. then cd <app_name> to load your new gemset. It will prompt you with a "Your .rvmrc file has been modified." Just press y and press enter.
  7. Run rvm current which should print something along the lines of ruby-1.9.3-p194@<app_name>. You're good to go.

Short segue on what just happened. RVM manages all your "gems" for you, which are just collections of code that do useful things. Rails is distrubuted as a gem, though gems are a way of distributing arbitrary Ruby code, not just Rails stuff. RVM can manage different sets of gems for every project. By putting rvm 1.9.3@<app_name> --create in your .rvmrc means that rvm will run that command everytime you enter that directory. The command essentially says "use ruby version 1.9.3, and use the gemset called <app_name>, and if it doesn't exist yet then create it." This will help you not to have conflicting versions of gems across different Rails projects.

  • Run bundle install. This will take a little while (maybe a minute or two).

  • Once that's done, you're good to go! Now run rails server and you should see something like this print out:

=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-09-17 21:57:33] INFO  WEBrick 1.3.1
[2012-09-17 21:57:33] INFO  ruby 1.9.3 (2012-04-20) [x86_64-linux]
[2012-09-17 21:57:33] INFO  WEBrick::HTTPServer#start: pid=14184 port=3000

Now open a browser and go to localhost:3000 and you should see the Rails start page. You're ready to build your own apps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment