Hello buddy, if you are here, it is probably because you have just acquired a new computer equipped with a new chip from Apple, the M1/M2. Know that in addition to being a marvel of modern technology and engineering, this super machine is also capable of keeping you awake with a multitude of crazy, and sometimes inexplicable, problems that will prevent the correct installation of various software.
This guide assumes that the machine has not yet had any systems installed, and all the steps for installing them will be described here in the order in which they were done by me until I was successful in this endeavor.
This guide also assumes that you’re using zsh
. If not, replace any references to .zshrc
in the steps below with .bash_profile
(if you’re using Bash) or the appropriate shell.
That said, let's play?!
Before you start, make sure you have the latest Apple software updates for your current macOS version. Click on the Apple icon in the top left of your screen, then click on System Preferences, and then click on Software Update. If there are any updates available, install them. If you already have the latest updates for the current macOS version, you don’t have to upgrade to the latest macOS.
If you’re on an Apple Silicon Mac, make sure Terminal is NOT in Rosetta mode, you can check it by running this command inside Terminal:in the Terminal app:
uname -m
As you are on an Apple Silicon Mac, It should say arm64
. If receive x86_4
, that means Terminal is in Rosetta mode. The only way this could happen is if you changed the setting yourself, most likely after following incorrect or outdated advice (Don't judge yourself, I did that too), so, to turn off Rosetta, follow these instructions:
- Quit Terminal if it’s running
- Go to the Finder
- Go to the Utilities folder by pressing shift-command-U (or select “Go” from the menu bar, then select Utilities)
- Select Terminal, but don’t launch it. Just click once to select it.
- Press command-i (or from the menu bar: “File”, then “Get Info”)
- Uncheck the checkbox that says “Open using Rosetta”
- Close the Terminal Info window
- Launch Terminal
- Run uname -m. It should now say arm64 and you can proceed with the rest of this guide.
If you haven't tried to install Homebrew yet you can just skip this section, but if you’re not sure, check the contents of the /usr/local
folder by running this command in the Terminal app:
ls /usr/local
If there’s nothing in the folder, then you don’t have Homebrew. But, if you’re on a Mac with the Apple Silicon chip (M1/M2), which is probably the case, you’ll also need to check the /opt/homebrew
folder:
ls /opt/homebrew
If those folders are not empty, that means Homebrew is installed, and you’ll need to make sure that Homebrew is happy by running this command:
brew doctor
It should say Your system is ready to brew
.
If it’s not ready to brew, then read what Homebrew has to say and see if you can fix the issues on your own.
For the purpose of this guide, installing Homebrew will be done just by running the command that’s listed at the top of the Homebrew site:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Please note that the command listed on the Homebrew site could change, so please make sure that what is listed above is the same. If it isn’t, please update it for future use.
On Apple Silicon Macs, Homebrew might tell you to run a few commands after the installation, such as:
echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.zprofile
eval $(/opt/homebrew/bin/brew shellenv)
Make sure to run those commands and once the installation is successful, ç, then check if Homebrew is ready to go:
brew doctor
It should say Your system is ready to brew
.
Of all the Ruby managers, I recommend asdf
because in my opnion it’s the most stable and easiest to use and maintain. Ruby managers are not compatible with one another, so if you have RVM, rbenv, or chruby, you’ll need to uninstall them.
Of course you can choose to continue with your favorite manager, if that is the case you can skip this asdf installation section and proceed with the installation of your preferred one.
Install asdf
and dependencies:
brew install xz asdf [email protected] readline libyaml
Adds asdf
to the zsh shell, enables asdf recognition of .ruby-version
and exports the openssl path to make it possible to install and build it's gem:
echo ". $(brew --prefix)/opt/asdf/libexec/asdf.sh" >> ~/.zprofile
echo "legacy_version_file = yes" >> ~/.asdfrc
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"
After that, restart Terminal.
Adds ruby plugin to asdf, install ruby and set it as asdf's global ruby
asdf plugin add ruby
asdf install ruby 3.1.2
asdf global ruby 3.1.2
Now, if you restart your Terminal and run ruby -v
, it should print something like:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
Here, we are also using asdf
as a NodeJs version manager, so to install it follow the commands below:
asdf plugin add nodejs
brew install node-build
asdf install nodejs 16.13.2
asdf global nodejs 16.13.2
Now, just like we did after installing Ruby, let's restart the Terminal and then run node -v
, it should print something like:
v16.13.2
Install now yarn
and postgres
by running brew command:
brew install yarn
brew install postgresql@14