I bought an M1 Mac mini, so I tried installing Ruby and Rails. In conclusion, as of January 2021, you can install it with Homebrew and rbenv without any problems. However, there is something strange about how Rails (development environment) works. Also, you may get an error when compiling 2.6.6.
Environment: Apple M1, macOS Big Sur, Ruby 2.6.6/2.7.2/3.0.0, Rails 6.1.0
Run the following command: The dialog "You need a command line developer tool to execute the" clang "command. Do you want to install the tool now?" Is displayed. Press "Install".
% clang
The same is true if you run the following command: You don't need to install Xcode.
% xcode-select --install
Install Homebrew by copying the command from the Homebrew site (https://brew.sh/).
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Unlike Intel Mac, the installation directory will be / opt/homebrew
, so add the Homebrew bin directory to the environment variable PATH. Edit .zshrc and reopen the terminal.
.zshrc
export PATH="/opt/homebrew/bin:$PATH"
Install ruby-build and rbenv.
% brew install ruby-build rbenv
Install OpenSSL 1.1.
% brew install openssl
Write the OpenSSL and rbenv settings in .zshrc. You can install the other environment variables you need without writing them. Reopen the terminal.
.zshrc
export PATH="/opt/homebrew/bin:$PATH"
export PATH="$(brew --prefix [email protected])/bin:$PATH"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"
eval "$(rbenv init -)"
Install Ruby with rbenv.
% rbenv install 2.7.2
Set the Ruby version to 2.7.2 with rbenv.
% rbenv local 2.7.2
Check the Ruby version. Look at the display "arm64" and get rid of it.
If the system ruby command (/ usr/bin/ruby) remains, reopen the terminal.
% ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]
Ruby 3.0.0 is also included.
% rbenv install 3.0.0
2021-01-12 Addendum: Ruby compilation failed when installing 2.6.6 with rbenv. I'm getting the following error in the log: Failed in ext/fiddle/closure.c.
closure.c:264:14: error: implicit declaration of function 'ffi_prep_closure' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
result = ffi_prep_closure(pcl, cif, callback, (void *)self);
To prevent this, first install libffi with Homebrew.
% brew install libffi
Set the environment variable PKG_CONFIG_PATH to use libffi installed by Homebrew.
.zshrc
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
See also: https://github.com/rvm/rvm/issues/4968
I will raise the version of Bundler.
% gem install bundler -N
In the case of Ruby 3.0.0, bundle install will fail to install nokogiri, so specify the option first and install it (as of January 02, 2020).
% gem install nokogiri -- --use-system-libraries
Install the latest version of Rails. The -N option omits the ri documentation to speed up the installation.
% gem install rails -N
Check the version. If it's still in the system rails command (/ usr/bin/rails), reopen the terminal.
% rails --version
Rails 6.1.0
Install yarn.
% brew install node yarn
Let's create a new application.
% rails new generic
Launch the application.
% cd generic
% bin/rails s
I can access the page at http: // localhost: 3000 /
, but I keep getting the following error (as of January 02, 2020).
E, [2021-01-02T20:15:05.838500 #91997] ERROR -- : Exception rescued in listen-worker_thread:
Errno::EBADARCH: Bad CPU type in executable - /Users/kazuto/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rb-fsevent-0.10.4/bin/fsevent_watch
/Users/kazuto/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rb-fsevent-0.10.4/lib/rb-fsevent/fsevent.rb:140:in `popen'
To prevent this, change config.file_watcher
in the development environment settings.
config/environments/development.rb
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.file_watcher = ActiveSupport::FileUpdateChecker
Install version 11 of PostgreSQL.
% brew install postgresql@11
Add the version 11 path in .zshrc. With this alone, the gem pg can be compiled.
.zshrc
export PATH="/opt/homebrew/bin:$PATH"
export PATH="$(brew --prefix [email protected])/bin:$PATH"
export PATH="$(brew --prefix postgresql@11)/bin:$PATH"
#The following is omitted
Start PostgreSQL.
% brew services start postgresql@11
Install MySQL 5.7.
% brew install [email protected]
Add the path in .zshrc.
.zshrc
export PATH="/opt/homebrew/bin:$PATH"
export PATH="$(brew --prefix [email protected])/bin:$PATH"
export PATH="$(brew --prefix postgresql@11)/bin:$PATH"
export PATH="$(brew --prefix [email protected])/bin:$PATH"
#The following is omitted
Start MySQL.
% brew services start [email protected]
When I install mysql2 of gem with bundler, I get the error ld: library not found for -lssl
(as of 2021/01/02). Install mysql2 with options first.
% gem install mysql2 -- --with-opt-dir="$(brew --prefix [email protected])"
MySQL 5.7 should require a password, but if you install it with Homebrew, you can use it without a root password. To make the password mandatory, set it with the following command.
% mysql_secure_installation
Recommended Posts