Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install gem from command line vs changing gemfile

I'm trying to understand what exactly happen when I'm installing gems. At first I thought that using the "gem install gem_name" command (and after it the "bundle install) will make sure I have the proper files and dependencies and then it will update the gemfile.

But I've noticed that whenever I add gem using the commend line it doesn't appears at the gemfile yet I'm still able to use its functionality.

so is there is any reason to use the comment "gem install gem_name" insted of just adding the gem name to the gemfile?

like image 634
shultz Avatar asked Sep 02 '13 13:09

shultz


People also ask

How do you install gems you added to your Gemfile?

run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.

What is the difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.


1 Answers

The reason to use a Gemfile is that you can install all required gems in a single go.

Imagine that you work in a development team and a new member starts contributing to your application.

Al he has to do is checkout the repository and run bundle install.

Only use the command gem install if you just want to install a gem that is not nessecarily relevant to your project.

If the project requires the gem; put it in the Gemfile.

like image 122
Arjan Avatar answered Sep 27 '22 20:09

Arjan