Mac with M1 chip (M1 Mac) using homebrew, a package management tool for macOS The procedure for building a development environment for Ruby on Rails is described above.
It is based on MacBook Pro environment construction procedure with M1 chip.
Development environment for M1 Mac is a good reference for building a general-purpose environment on M1 Mac. (Since MacPorts is used for package management instead of Homebrew, that part is It is not very helpful when building an environment with Homebrew. )
About building an environment with Homebrew on M1 Mac I wrote Development environment on M1 Mac with Homebrew.
Homebrew uses the features of Xcode to compile software, so first Install Xcode and Command Line Tools for Xcode.
Install via the App Store.
Start Xcode and select Xcode => Open Developer Tool => More Installed from the page displayed by clicking Developer Tools Download and install the CLT for your Xcode version.
For M1 Mac, for now, the traditional installer is not available, except when using Rosetta2. You can not use it. Aside from the traditional installer, a package for M1 Mac (M1 Mac version) Is prepared.
Installation of the M1 Mac version can be found on the official homepage Alternative tetrahydrofuran. As you can see, the procedure is to extract a set of Homebrew tarballs to/opt/homebrew.
Under/opt/homebrew instead of under/usr/local /, which is the traditional installation destination The installation to is working well if you put it under/usr/local / It seems that there are cases where it is not done.
Intel Mac version under/usr/local, M1 Mac version under/opt/homebrew It seems that it is supposed to be installed and used together. (Personally, I don't recommend using the Intel Mac version and the M1 Mac version together.)
Currently, Intel Mac version and M1 Mac version are separated, and M1 Mac uses under/opt/homebrew. What we are doing is that it takes time to make the installer and the main unit compatible with both Intel and M1 As a result of temporary measures to provide Homebrew as soon as it becomes an M1 Mac, I can think of it.
Once Homebrew is compatible with both Intel and M1, users will be able to use Intel Mac or M1 Mac. You can install Homebrew without being aware of it, and install it under/usr/local You should be able to use the provided software.
Create/opt/homebrew.
Since/opt is under the control of the root user, it cannot be tampered with by the logged-in user. Create a directory as root user with sudo & in the created directory Set the ownership of the logged-in user.
After installation in/opt/homebrew, in .zshrc (if shell is zsh) Add the path to Homebrew and reflect it in the shell.
Make sure you have the path to Homebrew, then install Homebrew I will update it.
% cd /opt
% sudo mkdir homebrew
% sudo chown -R $USER .
% curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
% vi ~/.zshrc
export PATH=/opt/homebrew/bin:$PATH
% source ~/.zshrc
% brew -v
% brew update
Install rbenv and ruby-build with Homebrew.
The path to rbenv and the rbenv initialization command at shell startup .zhrc (if the shell is zsh) Add to and reflect in the shell.
RBENV_ROOT is set to the directory where rbenv is installed. With this set, rbenv was installed when ruby was installed with rbenv. Ruby will be installed in the directory.
If RBENV_ROOT is not set, when installing ruby with rbenv Ruby will be installed under Users/[login username] /. Rbenv.
Make sure the path is in rbenv.
% brew install ruby-build
% brew install rbenv
% vi ~/.zshrc
export PATH=/opt/homebrew/bin:$PATH
export PATH="/opt/homebrew/sbin:$PATH"
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"
% source ~/.zshrc
% rbenv
Since openssl and readline are required to install ruby, use Homebrew Install it.
Set the path to openssl and the environment variables required for ruby compilation for openssl Add it to .zhrc (if the shell is zsh) and reflect it in the shell.
Check the installable version with rbenv, and check the version to install Select and install.
Update shims in rbenv.
Set the version of Ruby to work with rbenv.
Make sure that the version of Ruby you set is working.
%brew install readline
%brew install openssl
% vi ~/.zshrc
export PATH=/opt/homebrew/bin:$PATH
export PATH="/opt/homebrew/sbin:$PATH"
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"
% source ~/.zshrc
% rbenv install —-list
% rbenv install 2.7.2
Installed ruby-2.7.2 to /opt/homebrew/opt/rbenv/versions/2.7.2
% rbenv rehash
% rbenv global 2.7.2
% ruby -v
Update RubyGems and Bundler pre-installed in Ruby to the latest version.
% gem update --system
% gem update bundler
For Javascript package management in Ruby on Rails projects Since Node.js and Yarn are used in Webpacker etc, Node.js and Yarn is also installed.
% brew install node
% brew install yarn
Not related to Ruby on Rails so far, but the same Javascript execution environment as Node.js is.
Continued here
I'm using Capybara for system testing in a Ruby on Rails project In some cases, Capybara depends on Nokogiri gem, which is used in the backend. These native libraries must be installed in advance.
Also, the path to these libraries and the programs that use these libraries Add the environment variable settings required at compile time to .zhrc (if the shell is zsh) and Reflect in the shell.
Bundler nokogiri installs these libraries with Homebrew Set to use during installation.
% brew install libxml2 libxslt libiconv
% vi ~/.zshrc
export PATH=/opt/homebrew/bin:$PATH
export PATH="/opt/homebrew/sbin:$PATH"
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"
export PATH="/opt/homebrew/opt/libxml2/bin:$PATH"
export LDFLAGS="$LDFLAGS -L/opt/homebrew/opt/libxml2/lib"
export CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/libxml2/include"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/libxml2/lib/pkgconfig"
export PATH="/opt/homebrew/opt/libxslt/bin:$PATH"
export LDFLAGS="$LDFLAGS -L/opt/homebrew/opt/libxslt/lib"
export CPPFLAGS="$CPPFLAGS -I/opt/homebrew/opt/libxslt/include"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/libxslt/lib/pkgconfig"
export PATH="/opt/homebrew/opt/libiconv/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/libiconv/lib $LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/libiconv/include $CPPFLAGS"
% source ~/.zshrc
% bundle config build.nokogiri --use-system-libraries \
--with-xml2-include=$(brew --prefix libxml2)/include/libxml2
Use Selenium WebDriver for system testing in Ruby on Rails projects The ffi gem on which this gem depends is using it in the backend The native library must be installed in advance.
Also, the path to libffi and required when compiling programs using this library Add the setting to the environment variable to .zhrc (if the shell is zsh) and reflect it in the shell.
% brew install libffi
% vi ~/.zshrc
export PATH="/opt/homebrew/opt/libffi/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib $LDFLAGS"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/libffi/lib/pkgconfig"
% source ~/.zshrc
Use sassc-rails gem to compile Sass in Ruby on Rails project When doing, sassc-ruby used by this Gem is used in the backend LibSass must be installed in advance.
Up to Rais 5.0, sass-rails was widely used, but this Gem is using it. Since sass-ruby has been deprecated by the Sass team, after that It is recommended to use sassc-rails.
The other day, the Sass team deprecated LibSass, which is the reference implementation of Sass. Announcing recommendations for Dart Sass.
From now on, LibSass will be in maintenance mode, no new features of Sass will be added, only bug fix Please note that it will be done.
You may want to consider using Dart Sass via WebPacker.
% brew install --build-from-source libsass
Gem etc. that uploads and displays images in the Ruby on Rails project Native that those gems use as a backend when using The library must be installed in advance.
ImageMagick used by Refile and CarrierWave has a Homebrew package. It seems to be M1 compatible, so it can be installed. (Installation failed several times After (I got rid of it on the way), the installation was successful, so I'm not sure if M1 support is complete. )
The image_processing gem used by ActiveStorage is the backend You can choose ImageMagick or libvips, development using Active Storage When doing it, I decided to use ImageMagick or libvips as the back end Become.
libvips can also be installed because the Homebrew package seems to be M1 compatible.
% brew install imagemagick
% brew install vips
Install the standard Git source code control tool.
% brew install git
Install PostgresSQL and MySQL.
I was able to install PostgreSQL smoothly, so the latest version of Homebrew The package seems to be M1 compatible.
MySQL has been installed several times before successful installation, and then Homebrew I was able to install it with package version 8.0.22_1. 5.x is still currently It seems that M1 is not supported, so be careful when using MySQL on M1 Mac.
PostgreSQL makes macOS login user superuser at installation It is set, but it is not good to operate PostgreSQL as a logged-in user So create a user postgres for operation, give it superuser privileges, Allow the postgres user to operate PostgreSQL.
Add the PostgresSQL data storage path to .zhrc (if the shell is zsh) and After applying to the shell, create a PostgresSQL database cluster.
Immediately after installing MySQL, the root user (superuser) has a password Since it is not set, hit mysql_secure_installation to secure it Let's strengthen it.
% brew install postgresql
% brew install mysql
% brew services start postgresql
% psql -U${USER} postgres
postgres=# create user postgres with SUPERUSER;
postgres=# exit
% brew services stop postgresql
% vi ~/.zshrc
export PGDATA="/opt/homebrew/var/postgres"
% source ~/.zshrc
% rm -rf /opt/homebrew/var/postgres
% brew services start postgresql
% initdb -U postgres --encoding=UTF-8 --locale=ja_JP.UTF-8
% brew services stop postgresql
% brew services start mysql
% mysql_secure_installation
% brew services stop mysql
Docker for building development / execution environment in development project using Ruby on Rails I may be using it.
Continued here
What is the minimum installation procedure for the Ruby on Rails development environment on M1 Mac? that's all.
After that, install the necessary things in each environment and customize the development environment let's go.
Recommended Posts