The original article is reprinted from Liu Yue’s Technology Blog https://v3u.cn/a_id_188

In each developer, there will be a “best” language, in the depths of one of the world in some proper pose no group of people, the name of this language is called Ruby, it was twenty-eight years old this year, the same long history and Java, but it has no big endorsement, its performance is for developers, today will not be able to efficiently use of multi-core resources, It even dies every year. Compared to Java, which is supported by Sun Computer Systems, Oracle, and IBM, it has nothing, but it has the most devout “believers” in the world and the most active developer community, which makes it have everything. Yes, this is the philosophy of Rubyist: sometimes you want to prove it to ten thousand people, but then you only find that one person who understands is enough.

This time, we try to build the latest version of Ruby3.0.0 and Web development framework Rails6.1.1 in the latest M1 chip Mac OS (Big Sur 11.2.2). A new chip, a new journey and a new start:

First, let’s look at the command line on the M1 chip. If you’re migrating from an older Mac, such as Mojave, it’s best to replace the old Base command line with ZSH, a shell system that is much more powerful than bash. It can serve as both an interactive terminal and a script interpreter. Replace necessity here means that some unknown error may occur if you compile Ruby3.0 with Bash. Execute the command toggle ZSH:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

After the installation is successful, make sure that Rosetta is not checked in the Introduction of Application – Utility – Terminal – because we will need to install Homebrew with ARM architecture, so all compilation and run actions do not need Rosetta:

Then restart the terminal and install the AMR architecture of Homebrew:

/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"

Then edit the configuration file ~/.zshrc and add the following:

path=('/opt/homebrew/bin' $path)  
export PATH

Execute the command after saving:

source ~/.zshrc

View the location of new brew:

➜  ~ which brew  
/opt/homebrew/bin/brew

/opt/homebrew/bin/brew = /opt/homebrew/bin/brew = /opt/homebrew/bin/brew

➜ ~ BREW Cleanup && BREW Update Already Up-to-Date

If you do not have an agent, you can choose to set the domestic source:

# brew  
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git  
  
# core  
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git  
  
# cask  
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git  
  
  
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zprofile  
source ~/.zprofile

In this case, we use rbenv, which is a multiversioning package similar to Python Conda. It is easy for older projects to run in lower versions of Ruby, such as Ruby2.6.

Ruby relies on the OpenSSL and Autoconf packages, which are pre-installed. If you migrated from OpenSSL to a lower version, it is best to reinstall the latest version 1.1j:

Brew reinstall [email protected] brew reinstall autoconf

Then install rbenv and execute the command:

brew install ruby-build rbenv

Then add the rbenv command to the ZSH command line environment variable:

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc  
source ~/.zshrc

Restart the command line and type rbenv:

➜ ~ rbenv rbenv 1.1.2 Usage: rbenv <command> [<args>] Some useful rbenv commands are: commands List all available rbenv commands local Set or show the local application-specific Ruby version global Set or show the global Ruby version shell Set or show the shell-specific Ruby version install Install a Ruby version using ruby-build uninstall Uninstall a specific Ruby version rehash Rehash rbenv shims (run this after installing executables)  version Show the current Ruby version and its origin versions List installed Ruby versions which Display the full path to an executable whence List all Ruby versions that contain the given executable

If you return the version number and the associated actions, it’s not a problem, but it’s best to check with a script to make sure you don’t have problems with subsequent compilations:

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

Diagnostics do not report an error:

➜ ~ curl - fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash Checking for ` rbenv 'in the PATH:  /opt/homebrew/bin/rbenv Checking for rbenv shims in PATH: OK Checking `rbenv install' support: multiple You seem to have multiple `rbenv-install' in the following locations. Please pick just one installation and remove the others. /Users/liuyue/.rbenv/plugins/ruby-build/bin/rbenv-install /opt/homebrew/bin/rbenv-install Counting installed Ruby versions: 1 versions Checking RubyGems settings: OK Auditing installed plugins: OK

Next, due to well-known academic issues, rbenv is very slow to download binary installers, so we can download them manually by using a domestic mirror: https://cache.ruby-china.com/…

Download Ruby3.0 here:

Then manually copy the package to the rbenv installation directory: ~/.rbenv/cache

Rbenv /cache may not exist, so you can create it by hand:

mkdir ~/.rbenv/cache

Copy the installation package:

Cp ~ / Downloads/ruby - 3.0.0. Tar. Gz ~ /. Rbenv/cache/ruby - 3.0.0. Tar. Gz

Then we can finally install the Ruby3.0 ontology:

The brew link openssl -- force RUBY_CONFIGURE_OPTS = - with openssl - dir = / opt/homebrew/Cellar/[email protected]/1.1.1 j rbenv install 3.0.0

Since I have installed OpenSSL before, this time it is mandatory to specify OpenSSL with the ARM architecture to compile and install.

After successful installation, type rbenv versions:

➜ ~ rbenv versions * system (set by/Users/liuyue /. Rbenv/version) 3.0.0

As you can see, in addition to the default version of the M1 system, there is a version 3.0.0, and we can use the rbenv global command to switch versions:

➜ ~ rbenv global 3.0.0 ➜ ~ rbenv versions system * 3.0.0 (set by/Users/liuyue /. Rbenv/version)

Then type ruby-v:

➜ ~ ruby-v ruby 3.0.0p0 (2020-12-25 Revision 95Aff21468) [arm64-darwin20]

You can see that the version has been switched to 3.0, and the kernel version is ARM64 bit. If you want the system default version, you can also cut back:

➜ ~ rbenv global system nix ~ ruby-v ruby 2.6.3p62 (cial04-16 revision 67580) [universal. ARM64E-darwin20]

The default is Ruby 2.6.3, so it’s best to leave it alone.

Then we can install Rails:

Gem install rails -v 6.1.1

After successful installation, refresh:

rbenv rehash

Then check the version number:

➜ ~ rails -v rails 6.1.1 nil ~

Create a new project:

rails new myrails

Enter the project directory:

cd myrails

Start-up service:

rails s

A thousand calls to come out:

Conclusion: As a language of the same age, if Java is shining in the sky, then Ruby is burning in the ground, equally great but different. In fact, Ruby as a scripting language is more in contrast to Python. Python has made tremendous strides in data analysis and deep learning in recent years, leaving Ruby to be the dominant package manager on the Mac. Just as you can’t avoid Homebrew on the Mac, you can’t avoid Homebrew on the Mac. Many people bad-mouthing Ruby, think it is out of date, while in the heart of Rubyist on the contrary, it is so advanced, it is like M1 chip, is beyond the product of The Times, maybe one day, it will “die”, but won’t be today, finally, in the 19th century American novelist Herman Melville in moby-dick section and you email:

“Some died in the ebb tide; Some died in the shallows; Some people died in the flood.” “– Ahab, in Chapter 135, to Starbuck, his mate, as he pursued the White Whale for the last time.

The original article is reprinted from Liu Yue’s Technology Blog https://v3u.cn/a_id_188