Published on

Understanding Gem with prior knowledge of npm

Authors
  • avatar
    Name
    hwahyeon
    Twitter

A Gem is a package (library) used in the Ruby ecosystem. It is similar to npm packages in the JavaScript/Node.js ecosystem, containing reusable code written in Ruby. Examples of popular Gems include Jekyll, Rails, and Devise.

CategoryGemnpm
LanguageRubyJavaScript/Node.js
Package ManagerRubyGems (gem command)npm (npm command)
Dependency ToolBundlernpm
Dependency FilesGemfile, Gemfile.lockpackage.json, package-lock.json
Execution Commandbundle exec [command]npx [command]
Global Installgem install [package_name]npm install -g [package_name]
Project Installbundle installnpm install
Script Executionbundle exec for Gems (e.g., Jekyll, Rails)npm run [script_name]
Package Deploymentgem build [package_name].gemspecgem pushnpm publish
Package StructureA RubyGem consists of Ruby code and a .gemspec fileAn npm package consists of package.json and related files
Version SpecificationSpecify versions in the Gemfile (gem 'package_name', '~> 2.0')Specify versions in package.json ("package_name": "^2.0.0")
Local ExecutionExecute Gems with bundle execUse npx or run from the project's node_modules folder