M1 Mac に Rails 環境を構築する
home brew
インストール
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
rbenv
https://github.com/rbenv/rbenv#installation
インストール
brew install rbenv
brew upgrade rbenv ruby-build
rbenv init
RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install [version]
rbenv global [ver]
rbenv local [ver]
ruby -v
mysql
インストール
brew install --build-from-source mysql@[ver]
echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
source .zshrc
brew services restart mysql@[ver]
mysql -uroot
メモ
If you need to have mysql@5.7 first in your PATH, run: For compilers to find mysql@5.7 you may need to set: export LDFLAGS="-L/opt/homebrew/opt/mysql@[ver]/lib" export CPPFLAGS="-I/opt/homebrew/opt/mysql@[ver]/include" For pkg-config to find mysql@5.7 you may need to set: export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql@[ver]/lib/pkgconfig"
nodebrew
https://github.com/hokaccha/nodebrew
インストール
brew install nodebrew
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> .zshr
source .zshrc
Node.js
インストール
nodebrew setup
nodebrew compile v[ver]
nodebrew use v[ver]
node -v
Yarn Version Manager (yvm)
インストール
brew install tophat/bar/yvm
Run the following command to configure your shell rc file
node "/opt/homebrew/opt/yvm/yvm.js" configure-shell --yvmDir "/opt/homebrew/opt/yvm"
See "/opt/homebrew/opt/yvm/.config" for examples.
If you have previously installed YVM, link the versions folder
to allow all brewed YVM access to the managed yarn distributions
ln -sF ~/.yvm/versions /opt/homebrew/opt/yvm
yvm version
brew upgrade yvm
yarn
インストール
yvm install [ver]
以下の様に表示された場合、一度ディレクトリを削除する
EEXIST: file already exists, mkdir '/opt/homebrew/Cellar/yvm/4.1.4/versions'
yvm use [ver]
yarn -v
puma-dev
インストール
brew install puma/puma/puma-dev
puma-dev -install -d test
vim ~/.puma-dev/oatnd
3000 と記載する
rails
インストール
active_storageのイメージデータ
storage.zip
解凍してルート直下に配置する
gem mimemagicのライセンス問題対応
https://qiita.com/ShioriPeace/items/9c50d3bc90bbf7101c0a
brew install shared-mime-info
gem install mimemagic -v '0.3.10' --source 'https://rubygems.org/'
gem mysqlのインストールエラー対応
https://qiita.com/HrsUed/items/ca2e0aee6a2402571cf6
bundle config --local build.mysql2 "--with-ldflags=-L/opt/homebrew/opt/openssl@1.1/lib"
bundle config --local build.mysql2 "--with-cppflags=-I/opt/homebrew/opt/openssl@1.1/include"
bundle install
https://bundler.io/man/bundle-install.1.html
gem install bundler
bundle config set --local path 'vendor/bundle'
bundle install
webpacker インストール
bundle exec rails webpacker:install
Rails の起動
bundle exec rails s