As you pointed out, the contents of Bundler have been revised.
When creating the portfolio, I was building various environments.
What is a Gemfile?
I did it without knowing it in the tutorial, but I would like to summarize it here.
What is Gemfile? \ _ Hehe (∀ ｀ *) Katata
"Gemfile" is a file that manages the list of gems used in Rails application. Quote
gem is a ruby library. Quote
A file that collects a lot of useful program parts and puts them together. Quote
・ ・ ・ ・ Words that I don't understand appear in the Imozuru formula.
Related keywords: Gemfile, Gemfile.lock, bundler, library, gem
Let's summarize the above keywords into a story.
I have a man. A family of four with a wife and two children. His wife is tired of being busy with housework every day. Dad and children plan to "help mom and make it easier."
The purpose was to "make mom easier" (application)
There are various ways to do this, you can think for yourself, or you can get various books (gems) from bookstores (sources in Gemfile) and get inspiration.
Dad makes an action plan on how to achieve his goals. (Gemfile)
[https://rubygems.org]"How to help washing ver2.0", "How to make delicious food ver3.5" from the bookstore Get "Assertive Relationships with Your Wife ver4.0" and "5 Ways to Get Your Mother's Mood Ver1.1"
Based on the blueprint, my dad gets a book at a bookstore (bundle install), Here the librarian checks the list (Gemfile.lock) of the books and versions that Dad already has. After that, he looks at the "Dad's Action Plan" and gives you a book that you don't have and a book that has a dependency on it. Finally, it updates the list of books owned by Dad (Gemfile.lock).
Three months later, the children will go get the book with their father's action plan and list.
Dad and children can accomplish the goal of "easing mom" with exactly the same plan.
A library is a collection of common processes packed into program parts.
This is an example book. "Make delicious food" "How to help with laundry" These are libraries. In other words, it is called "gem".
If the wisdom of these ancestors is not in the form of a book, you will have to create a "method for making delicious food" yourself, and you will have to devise a "washing method" yourself. But if it's a library, you can use these technologies just by bringing it as it is.
For a real Rails application "Connect to the database" "Test" "Adjust the appearance" "Implementation of login function" "Add pagination function"
Such "gem" is prepared.
There are dependencies in gems. For example, the book "Making delicious food" is supposed to refer to the book "How to use kitchen knives 2.0". (Depends on)
In this way, there are cases where gems use other gems.
bundle installYou can get the gem even if you don't.
gem's package manager "RubyGems"
The way to get a book is to go to a bookstore (
`https://rubygems.org```), but when you try to get "make delicious food",
gem install make delicious food" The `` command alone will give you" How to use a kitchen knife 2.0 ".
Then what is the significance of Bundler? It becomes a story.
Without Bundler, applications suddenly stop working, or in another person's environment .
why? The gem will be updated to make it better. When it is updated, it will not be compatible with the gems that have been dependent on it until now, and the above problems will appear.
Suppose your dad gets "how to cook delicious food" and its dependency "how to use a kitchen knife 2.0" with the gem command. Three months later, when the children also got it with the gem command, "How to use the kitchen knife" was updated. I got "How to make delicious food" and "How to use a kitchen knife 2.5", and the dependency is broken.
Bundler With the advent of Bundler, everyone who uses the application can run the app with the same gem version, including the dependent gems.
In the previous example, even if the author of "How to make delicious food" says "How to use a kitchen knife 2.0 or later", the father can control "How to use a kitchen knife 2.0!" Bundler ". This allows children (other developers) to prepare "How to use kitchen knives 2.0".
"Gemfile" and "Gemfile.lock" are required to manage the version with this Bundler.
Gemfile The place to manage gems installed by this bundler is "Gemfile"
A file that manages the list of "gems" used in Rails applications.
The source at the top is the code that specifies the bookstore, which comes out a little from the previous time.
I fetch various books "gem" from the bookstore. Rails, sqlite2, puma, etc. You can also specify the version with the second argument of the gem, as you can check the function of each gem.
|No arguments||Insert the latest ver|
|~>1.1||1.1 or later ~ 2.Limited to ver before 0|
|>=1.0||1.Limited to 0 or more vers|
Gemfile.lock This file shows a list of "gems" installed by bundler. Dependent gems are also displayed here.
For example, there is no "action cable" in "Gemfile", but since this is a gem that Rails depends on,
`bundle install` will show it in Gemfile.lock. (It is also installed with `` `gem install rails```)
If gem rails is mentioned in the Gemfile, rails and the action cable that rails depends on will be installed. Quote
This command "uses the gem written in Gemfile.lock".
Dad and children finally do "make mom easy". However, in fact, there were books in this house, "How to use a kitchen knife 1.0", "How to use a kitchen knife 1.67", and "How to use a kitchen knife 2.0". What I want to use is "How to use a kitchen knife 2.0", which is also written in "Gemlock.file".
If you don't use bundle exec, children will say "How to use kitchen knives 1".It is possible that "0" is seen and executed, and "make mom comfortable" fails.
Therefore, for example, in the case of ``` rails s```, it is necessary to use `` `bundle exec rails s```. # Impressions / Issues I tried to create an image to understand it within myself, but I cannot deny the feeling that it became redundant. Even "gems" like the basic knowledge of course are deep and I can't understand everything. (Whether the path option is needed during bundle install, etc.) I want to move forward little by little. You pointed out when you posted for the first time. I was completely misunderstanding about Bundler. Thank you for the opportunity to learn and modify. # Citation / Reference https://qiita.com/kamohicokamo/items/ded4cad5be1778547640 https://qiita.com/nishina555/items/1b343d368c5ecec6aecf#:~:text=Gemfile%E3%81%A8%E3%81%AF,%E7%AE%A1%E7%90%86%E3%81%95%E3%82%8C%E3%81%A6%E3%81%84%E3%82%8B%E3%81%AE%E3%81%8B%EF%BC%9F%E3%80%8F&text=%E3%81%A7%E3%81%99%E3%81%AE%E3%81%A7%E3%80%81Rails%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A7,%E3%81%84%E3%81%8F%E3%81%93%E3%81%A8%E3%81%AB%E3%81%AA%E3%82%8A%E3%81%BE%E3%81%99%E3%80%82 https://nishinatoshiharu.com/fundamental-gem-knowledge/ https://wa3.i-3-i.info/word1473.html https://pikawaka.com/rails/bundler http://xxxcaqui.hatenablog.com/entry/2013/02/11/013421 https://qiita.com/kaishuu0123/items/2a91495e7daa8c7783ed