Creating a New Application

In this lesson, we will learn to create a new Rails application.

When you install the Rails framework, you also get a new command-line tool, rails, that’s used to construct each new Rails application.

Why do we need a tool to do this? Why can’t we just hack away in our favorite editor and create the source for our application from scratch? Well, that is an option. After all, a Rails application is just Ruby source code. However, Rails does a lot of magic behind the curtain to get our applications to work with a minimum of explicit configuration. To get this magic to work, Rails needs to find all the various components of our application. As we’ll see later, this means we need to create a specific directory structure in which we slot the code we write into the appropriate places. The rails command creates this directory structure for us and populates it with some standard Rails code.

To create our first Rails application, pop open a shell window and navigate to a place in our filesystem to create our application’s directory structure. In this example, we’ll be creating our projects in a directory called work. In that directory, use the rails command to create an application called demo. Be slightly careful here. If there is an existing directory called demo, we’ll be asked if we want to overwrite any existing files.

Note: If you want to specify which Rails version to use as described in Choosing a Rails Version, now is the time to do so.

rubys> cd work
work> rails new demo create

Get hands-on with 1400+ tech skills courses.