Fast, Consistent Setup for Your Ruby and Rails Tools

After you build a few Rails apps, you’ll begin to have some preferred ways of working with them. Maybe you always want to use awesome_print in your Rails consoles. Or you might want rails new to create projects that use rspec instead of minitest.

Sure, it’s only a little annoying to have to specify these preferences each time you run a command. But they’re easy to forget. And it’s infuriating when a computer doesn’t do what you thought you told it to do:

$ rails new best_app_ever
^C (sigh...)
$ rm -r best_app_ever
$ rails new best_app_ever --template=my_template

There is an easier way. With a few small tweaks, you can have these commands remember your preferences, so you won’t have to.

Capture your preferences with .rc files

Lots of Ruby tools give you a simple way to store your preferences using .rc files.

.rc files live in your home directory:

$ ls ~/.*rc
.bashrc		.irbrc		.screenrc
.gemrc		.railsrc	.zshrc

and they give commands like gem, irb, and rails a place to find your preferences. Here are some .rc files you should try using:


When you run rails console, you might want to see all of your objects awesome_printed by default. You could type AwesomePrint.irb! at the beginning of each console session. Or, you can add the command to your ~/.irbrc file:

require "awesome_print"

And the next time you start a rails console, your objects will be printed more awesomely, automatically.

.irbrc is also a great place to put hacky convenience methods that help you play with your objects:

require "awesome_print"

# returns the instance methods on klass 
# that aren't already on Object
def m(klass)
  klass.public_instance_methods - Object.public_instance_methods
~/Source/rcfiles jweiss$ bin/rails c
Loading development environment (Rails 4.1.1)
irb(main):001:0> m ActiveRecord::Base
    [  0]                                        [](attr_name)                     ActiveRecord::Base (ActiveRecord::AttributeMethods) (unbound)
    [  1]                                       []=(attr_name, value)              ActiveRecord::Base (ActiveRecord::AttributeMethods) (unbound)
    [  2]                         _commit_callbacks()                            
... about 200 more methods...

When you customize your environment like this, you’ll begin to feel like the libraries you use are yours, instead of just libraries that you use.


Rubygems has its own .rc file to make dealing with gems more convenient. Lots of people use .gemrc to skip rdoc and ri generation, which makes gems install much faster:

gem: --no-document

But there’s a lot more you can do. There are a few other values you can tweak in your .gemrc, including :sources: (to look for gems on other gem servers) and :backtrace: (to see a full backtrace when errors occur):

gem: --no-document
:backtrace: true
- https://my.internal.gem.server

For the rest of the settings you can place in this file, take a look at the gem environment command documentation.


Years ago, Rails 3 made it easy to generate apps that don’t use the default Rails stack. If you want an app that doesn’t use minitest (so you can include rspec later, for example), it’s as simple as:

$ rails new my_awesome_app --skip-test-unit

Or maybe the place you work has their own project template:

$ rails new my_awesome_corporate_app --template=

Once you get familiar with a Rails stack, you’ll probably want to use it for all your new projects. But it’s easy to forget to add these parameters when you generate another app. Instead, you can put these parameters in a .railsrc file:


And now you can run rails new with the right parameters every time. And if you ever want to override those parameters for a single project, you can do it with --no-skip-test-unit-style commands.

Make your environment yours

A little up-front configuration work can make your environment feel more like home. You can skip the pain of accidentally running a command without the parameters you want. You don’t always have to dig up documentation to find the right options. And you can get to the fun part of writing code right away.

Did you like this article? You should read these:

Finished another Rails tutorial and still don't know how to start?

Have you slogged through the same guide three times and still can't retain enough to write apps on your own?

In my free 7-part course, you’ll discover the fastest way to learn and remember new Rails ideas, so you can use them when you need them. And you'll learn to use what you already know to build your own Rails project.