[FIXED] Difference among ruby gems, npm packages, and yarn

Issue

When I start a new Rails project, it gives me a template with a few different files for packages: Gemfile, package.json, and yarn.lock. I’m trying to understand if all three of these packages work together, or if I’m supposed to choose one. For example, in my Gemfile, I can add ‘jquery-rails’ but is this the same as installing jQuery to my package.json file? I’m having trouble understanding the difference between running bundle install and npm install.

Thanks.

Solution

In short it looks like this:

In Ruby, the bundler analyzes the list of libraries (gems) specified in the Gemfile, builds a dependency tree and fixes it in Gemfile.lock, downloads gems from different sources

In JS, various managers do the same: npm, yarn, bower, etc. By default Rails use yarn. They download all libraries to node_modules folder

package.json is analogue of Gemfile (but more advanced, for example you can define command line scripts there). yarn.lock is analogue of Gemfile.lock

Thus, bundler for Ruby and yarn / npm for JS libraries

Answered By – mechnicov

Answer Checked By – David Marino (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published