1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rails】Ruby On Railsでのgem管理方法

Last updated at Posted at 2020-10-01

1: gemインストールの流れ(詳細は2項目以降を参照)

Gemfileにインストールしたいgemを記述。
bundle installを実行。

$ bundle install

以上でインストール完了。

2: インストールに必要なもの

bundler

gem間の依存関係とバージョン管理を行うツール。

インストール方法

$ gem install bundler

念のため、インストールが成功しているかバージョン確認を行います。

$ bundle -v

Gemfile

インストールするgemを記述するファイル。
インストールしたいgemを列挙します。

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.7'  //これがgemに関する記述
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

Gemのインストール

以下のコマンドで、Gemfileに記述したgemをインストール・アップデートします。

$ bundler update

gemバージョンの書き方

Gemfileには、インストールしたいgemを列挙しますが、以下の記述でバージョンの指定等ができます。

バージョンの指定

gem "rails6" //rails6バージョンを指定
gem 'rails6’, '2.*.*' //rails6のさらに細かなバージョンを指定(*)には数字が入る
gem 'rails6’, '>=2.*.*' //rails6の特定のバージョン以上を指定(*)には数字が入る
gem 'rails6’, '~>2.*.*' //rails6の目ざーアップデートを規制(*)には数字が入る

gemfile.lockとは

bundler installでgemをインストールすると、gemfile.lockというファイルが生成されます。
インストールしたgemのバージョンを記載して保存します。
これにより、環境差でのgemバージョン違いによるエラーの発生を防ぐことができます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?