Creating a New Rails App without Installing the Gem

I usually keep a Gemset for each separate project I have. This means I have a lot of duplicate Gems across my system, but it has the advantage of keeping every project self-contained. This is especially useful since it means I can’t accidentally break a project by running bundle on some new project from Github.

This means I pretty much have no native Gems installed. But it can be a bit challenging to start a new Rails application, since there is no system rails command. So how do you avoid having to do a native install of Rails when starting a new project?

Here is the checklist I go through.

mkdir -p ~/my/new/project_name
cd ~/my/new/project_name

echo project_name > .ruby-gemset
echo 2.1.0 > .ruby-version
cd .

echo "source ''" > Gemfile
echo "gem 'rails', '~> 4.0.2'"      >> Gemfile
bundle exec rails new .

And there you have a brand new Rails app! Happy coding.