ローカル環境にrubyやmysqlがインストールしてあることが前提です。
$ mkdir sample-app
$ cd sample-app
$ bundle init
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "rails", "~>6"
bundle install --path vendor/bundle
bundle exec rails new . -B -d mysql --skip-turbolinks
- -Bはbundle installを行わないようにする
- -dはデータベースの指定(今回はmysql)
必要なgemをgemfileに追記
$ bundle install
このエラーが発生した場合
$ 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"
それでもダメな場合
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
$ bundle install --path=vendor/bundle
正しいかはわからないが、これでひとまずいけた。
webpackerを導入する場合(vueバージョン)
$ rails webpacker:install
$ rails webpacker:install:vue
$ rails s -p 3000