Rails 6.1.4.1 + Ruby 3.0.0 で新規プロジェクト作成手順

# はじめに
Rails 6.1.4.1 + Ruby 3.0.0 で新規Railsプロジェクトを作る手順のメモ。いろいろエラーが出たので備忘録。

# 1. RubyMineで新規プロジェクトを作成
## (1) bundle install
bundle install で以下のmysql2のインストールエラー。

```
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/ユーザー/RubymineProjects/プロジェクト/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.3/ext/mysql2
/Users/ユーザー/.rbenv/versions/3.0.0/bin/ruby -I /Users/ユーザー/.rbenv/versions/3.0.0/lib/ruby/site_ruby/3.0.0 -r ./siteconf20210821-60644-42muw5.rb extconf.rb --with-mysql-config\=/usr/local/Cellar/mysql@5.6/5.6.42/bin/mysql_config
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Cannot find mysql_config at /usr/local/Cellar/mysql@5.6/5.6.42/bin/mysql_config
-----

途中省略

extconf failed, exit code 1

Gem files will remain installed in /Users/ユーザー/RubymineProjects/プロジェクト/vendor/bundle/ruby/3.0.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/ユーザー/RubymineProjects/プロジェクト/vendor/bundle/ruby/3.0.0/extensions/x86_64-darwin-20/3.0.0/mysql2-0.5.3/gem_make.out

途中省略

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.

In Gemfile:
  mysql2
         run  bundle binstubs bundler
Could not find gem 'mysql2 (~> 0.5)' in locally installed gems.
       rails  webpacker:install
Could not find gem 'mysql2 (~> 0.5)' in locally installed gems.
Run `bundle install` to install missing gems.

Process finished with exit code 0

```

## (2) 解決方法
[参考記事](https://qiita.com/sun_peace/items/f06cc95e63a71b7296ec)の解決策をやって解決。

```
$ 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
```

# 2. config
## (1) database.yml
```ruby:config/database.yml
default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: <%= ENV.fetch('DATABASE_USER', '') %>
  password: <%= ENV.fetch('DATABASE_PASSWORD', '') %>
  host: <%= ENV.fetch('DATABASE_HOST', '') %>
```

## (2) msgpackをインストール
rakeを使う前にmsgpackをインストール

```
$ gem install msgpack
```

## (3) db:create & migration
DB作成してマイグレーション

```
$ rake db:create
Created database 'プロジェクト_development'
Created database 'プロジェクト_test'

$ rake db:migrate
```

## (4) webpackerをインストール

```
$ rails webpacker:install
✨  Done in 10.87s.
Webpacker successfully installed 🎉 🍰
```
# 3. Railsアプリを起動してブラウザで確認
```
/bin/bash -c "env RBENV_VERSION=3.0.0 /usr/local/Cellar/rbenv/1.1.2/libexec/rbenv exec ruby /Users/ユーザー/RubymineProjects/プロジェクト/bin/rails server -b 0.0.0.0 -p 3000 -e development"
=> Booting Puma
=> Rails 6.1.4.1 application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.4.0 (ruby 3.0.0-p0) ("Super Flight")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 67732
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop
```
![スクリーンショット 2021-08-21 午後11.30.51.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/329289/d40fc9e2-2a96-7430-d560-60c80ea968cf.png)

# 4. RailsアプリをGitHubにPush
[過去記事](https://qiita.com/NYC-Blue/items/79621264072685d3e009#11-rails%E3%82%A2%E3%83%97%E3%83%AA%E3%82%92github%E3%81%ABpush)の手順でPushする。