How to create a Gemfile?

I'm very new to Ruby.

I was following a blog post that says that in order to install a required dependencies I need to create a Gemfile.

How do I create a Gemfile with rspec as a dependency?


Solution 1:

bundle init generates a Gemfile into the current working directory.

$ bundle init
Writing new Gemfile to /app/Gemfile

$ cat Gemfile 
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# gem "rails"

Solution 2:

The Gemfile is just a text file within your project which contains a list of gems for use in your application.

If you do not have one in your application, you can create the file using an editor of your choice, saving it as Gemfile (with no extension), and in your example, containing:

source 'https://rubygems.org'

gem 'rspec'