LoginSignup
2
3

More than 3 years have passed since last update.

railsのローカルインストールを省力化

Last updated at Posted at 2019-08-14

概要

Railsのバージョンを複数入れると付随するgemのバージョンも複数となり気持ち悪い
対処方法を調べていたところ、こちらのサイトがとても参考になりました。
その中で繰り返しが面倒だと思った手順についてshell化したのでそのシェアになります。
(「RailsのローカルインストールとRailsプロジェクトの作成」の段)

前提

OS:Mac(Mojave)
Ruby環境:anyenv x rbenv

使い方

下記のshellをコピペして

./rails-new-blank.sh [railsのバージョン] [rails project名]

ex)
./rails-new-blank.sh 5.1.6 hello_app

shell本体

zsh準拠なので1行目は環境に合わせて書き換えてください

rails-new-blank.sh
#!/usr/local/bin/zsh

# 引数
# 1:rails version, 2:rails project name

# railsのみgemインストールするためのGemfileを作成
cat << EOS > Gemfile
source "http://rubygems.org"
gem "rails", "$1"
EOS

# railsをローカルにインストール
bundle install --path vendor/bundle

# rails projectを作成(bundle installはしない)
bundle exec rails new $2 --skip-bundle

# 片付け
# これでローカルにインストールしたrailsは削除
rm -f Gemfile Gemfile.lock
rm -rf .bundle vendor

# Gitの対象からローカルにインストールしたgemファイルを除外
cat << EOS >> $2/.gitignore

/vendor/bundle
EOS

参考

Rails開発環境の構築(rbenvでRuby導入からBundler、Rails導入まで)(Macport編)

2
3
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
2
3