LoginSignup
0
0

More than 3 years have passed since last update.

Rails6.0~ エコな開発環境の作り方

Last updated at Posted at 2020-10-04

クリーンな開発環境を実現する

Ruby on Railsの環境構築をできるだけエコ(環境汚染をせずに)作成する方法を備忘録として残しておきます。

もっとクリーンにできる方法があれば教えてください!

How To

1. 適当なディレクトリを作る

mkdir sample-app && cd sample-app

2. bundle initする

bundle init

3. Gemfileのrailsのコメントアウトをとる

Gemfile

# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "rails"

4. bundleの設定をする

bundle config set path 'vendor/bundle'

※bundlerがない場合はbundlerだけはグローバルインストールしてしまいましょう。

gem install bundler

5. railsをbundle install

bundle install

6. rails newでrailsアプリケーションの作成

bundle exec rails new . -B -d mysql --skip-test

-dでデータベース指定できるので適宜変えてください。

API作成の時は

bundle exec rails new . -B -d mysql --skip-test --api

--apiを付けてAPIモードにしましょう。

そしてGemfileが最初にinitで作成されたものとConflictしますがYを押してOverwrite。

7. rails new によって作成されたGemfileをもとに再度bundle install

bundle install

※mysql2インストール時にエラーが出る場合は以下を入力

bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include"
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

参照: https://qiita.com/fukuda_fu/items/463a39406ce713396403

8. webpackerのinstall

bundle exec rails webpacker:install

9. DB作成

bundle exec rails db:create

10. Yay! You’re on Rails!

スクリーンショット 2020-10-04 14.29.38.png

所感

まぁ一番はDocker使うのが環境を汚さない気がしますが...
Dockerを使わないなんてHow Dare You!と言われてしまう気がしますが、Dockerを使わないでローカルに環境構築する際の参考になれば幸いです〜

0
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
0
0