In this lesson, we will setup the project directory for our application along with Ruby's package manager tool called Bundler.

Note: I assume you have already installed Ruby on your machine. If not, download it using rbenv tool, which lets you manage multiple versions of Ruby.

Let's create a brand-new directory named weby (yes, it stands for web + ruby) and switch into it.

$ mkdir weby

$ cd weby

Next, we'll install bundler, a package (gem) manager for Ruby.

What's a gem?

A gem is a packaged Ruby application (similar to packages in JavaScript or PHP) that provides a specific functionality, such as logging, file upload, authentication, etc. When you build software, you install gems written by others instead of writing everything yourself.

What's bundler?

Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems that the application depends on. Its goal is to make sure that Ruby applications run the same code on every machine.

Given a list of gems, bundler can automatically download and install those gems, as well as any other gems needed by the gems that are listed.

Initialize Bundler for your project by running the following commands from the project's root directory.

$ gem install bundler

$ bundle init

It creates a Gemfile in the project. Whenever we want to use a gem in our project, we will add it to this file, and run bundle install command to install it.

For example, to install the devise gem:

# Gemfile

gem "devise"


# Terminal

$ bundle install

As a shortcut, bundler provides the bundle add command, which adds the gem to the Gemfile and runs bundle install for us. For example,

$ bundle add devise

You're now all set to install Ruby gems and start using them. In the next lesson, we'll install our first gem called Puma, an application server.