LoginSignup
16
14

More than 5 years have passed since last update.

新規Railsプロジェクト作成時のコマンド

Posted at

概要

bundlerを使用してプロジェクトローカルにgemをインストールする方針。
自分用メモ。

前提条件

  • rbenvでRubyインストール済み(Ver. 2.4.1)
  • gem install bundlerでbundlerインストール済み

コマンド

プロジェクトディレクトリ作成・移動
$ mkdir test_project
$ cd test_project
Gemfile作成
$ bundle init
Gemfile編集
$ vi Gemfile
Gemfile
source "https://rubygems.org"
gem "rails", "5.1.1"
Railsをパスを指定してbundle install
$ bundle install --path vendor/bundle
Railsプロジェクト作成
$ bundle exec rails new . -d postgresql --skip-bundle

※ --skip-bundleを指定しないとrails new時にbundle installが実行され、Ruby環境にgemがインストールされてしまう。
※ -dオプション: 使用するDBMSを指定。

プロジェクトローカルのgemでrails server起動
$ bundle exec rails s

無事起動すれば完了。

備考

bundle execで純粋にプロジェクトローカルのgemだけを使用するには、
.bundle/configのBUNDLE_DISABLE_SHARED_GEMSを"true"にすること。
"false"の場合、vender/bundle配下に存在しないgemをRubyグローバルから探してくる。

$ vi .bundle/config
.bundle/config
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_DISABLE_SHARED_GEMS: "true"  #ここを"true"
16
14
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
16
14