0
0
Ruby on Railsframework~30 mins

Gemfile and dependency management in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Managing Dependencies with Gemfile in Rails
📖 Scenario: You are building a new Rails application that needs some external libraries (gems) to add features like authentication and styling.To keep your project organized and ensure everyone uses the same versions of these libraries, you will use a Gemfile to manage dependencies.
🎯 Goal: Create a Gemfile with specific gems and versions, then configure and install them properly to prepare your Rails app for development.
📋 What You'll Learn
Create a Gemfile with exact gem entries
Add a Ruby version declaration in the Gemfile
Use bundle install to install the gems
Add a group block for development and test gems
💡 Why This Matters
🌍 Real World
Managing dependencies with a Gemfile is essential for any Rails project to ensure all developers use the same library versions and avoid conflicts.
💼 Career
Understanding Gemfile and dependency management is a fundamental skill for Rails developers, crucial for maintaining stable and secure applications.
Progress0 / 4 steps
1
Create the initial Gemfile with Ruby version and main gems
Create a Gemfile that specifies Ruby version '3.2.2' and includes these gems exactly: rails version '7.0.4', pg version '1.4', and puma version '5.6'. Write the lines exactly as shown.
Ruby on Rails
Need a hint?

Start your Gemfile by declaring the Ruby version with ruby '3.2.2'. Then add each gem with gem 'name', 'version'.

2
Add a group block for development and test gems
Below the existing gems, add a group :development, :test do block that includes the gems byebug version '11.1' and rspec-rails version '5.0'. Close the group block properly.
Ruby on Rails
Need a hint?

Use group :development, :test do to wrap gems used only in development and testing. Don't forget the end to close the block.

3
Run bundle install to install the gems
Run the command bundle install in your terminal to install all gems listed in the Gemfile and generate the Gemfile.lock file.
Ruby on Rails
Need a hint?

Open your terminal in the project folder and type bundle install to install the gems and create Gemfile.lock.

4
Verify the Gemfile.lock and finalize setup
Confirm that the Gemfile.lock file is created and add a comment in your Gemfile that says # Gems installed and locked at the end of the file.
Ruby on Rails
Need a hint?

Look for the Gemfile.lock file in your project folder after running bundle install. Then add the comment at the end of your Gemfile.