Brew M1



Friday, I received a snazzy new M1 Macbook Pro in the mail. This article outlines how I was able to set it up for doing web development. We'll set up Homebrew, PHP, MySQL, Composer, and Laravel Valet. Let's jump in!

  1. Brew M1 Status
  2. Brew M1 Compatibility
  3. Brew M1 Mac Install
  4. Mac M1 Install Homebrew
  5. Brew M1 Github
  6. Brew M1 Install

The previous article outlines first impressions from the perspective of someone upgrading from a 2013 mac.

Setting up an M1 mac for PHP development is not much different than other macs. Unless you're using Docker, which doesn't work on the new ARM processor (yet — they're working on it). I expected to have way more problems being an early adopter, but Apple has done a wonderful job with their Rosetta 2 translation layer. It mostly feels invisible, so (except for a few terminal commands like homebrew) you hardly even notice it is there.

Brew install -s -HEAD pkgnamehere. Nothing else needed. Honestly, the `-HEAD` part may not even be needed anymore. Realize the problem with homebrew isn't brew itself right now on the M1. I have absolutely zero doubt (go read the issues) the maintainers want to support it properly and be done with this kind of noise. Arch -x8664 brew tap freecad/freecad 4. Arch -x8664 brew install -s opencascade 5. Arch -x8664 brew install -s freecad 6. Freecad I found the above, allowing installation under Rosetta 2 emulation. What version of FreeCAD does that install?

Homebrew

Using the prefix arch -x8664 brew to your install command (and any subsequent brew commands). Now Homebrew is officially available for ARM64 Mac M1 computers, you can easily install on your Mac, and with the help of Homebrew you can build the packages from source code into ARM64 executable. Thanks for this. Got my dev environment back up well, the equivalent of it. I've been running stuff using vagrant and virtualbox. But virtualbox is not working. So I was able to recreate it using homebrew. Picked up the Mac mini M1 and it's been running great. Runs cool and fans have yet to spin. Can't say the same for my 2016 MBP i7. It works but hot and audible. – w1n78 Nov 18 '20 at 15:15.

First, we'll need to install Homebrew. They don't have an ARM-compatible build ready yet, so this is where we'll need to use some Rosetta flags on the command line.

Install Rosetta on the command line with the following:

/usr/sbin/softwareupdate --install-rosetta --agree-to-license

Next, add this function to your .zshrc file. It makes a nice arm alias for running commands with x86_64 architecture flags. Perhaps calling it x86 would be better? Shoutout to Matt Stauffer for posting this.

You'll need to run the homebrew commands with this prefix for now. We can copy the script from their site, add our arm prefix, and homebrew should install!

PHP, MySQL, and Composer

Now that homebrew is installed, the rest of the Valet install is pretty much stock (except for Redis, which we'll get to in the next section).

PHP

Just run arm brew install phpit's that easy! You may want to restart your terminal after this.

MySQL

Normal besides the arm prefix again.

Composer

Run the download script from Composer's website, then move the PHAR file to the bin folder. Also we'll add the global composer vendor folder to our system path.

Now add the following line to your .zshrc file

Brew M1

Valet and Redis

Installing Valet should work as normal now. Run the following commands:

After that, I also ran cd ~/Code && valet park .

Installing Redis

Redis presented the only real speed bump I've encountered thus far. It installs via brew, but starting the Redis server doesn't work correctly (even though brew says it does). Until then, we can start the server manually.

First, run arm brew install redis to install it.

Next, install the Redis PHP extension with PECL — pecl install redis.

Starting the Server

Normally you'd use arm brew services start to start Redis (and at login), but it's not working yet. That command just runs redis-server under the hood. For some reason, this command only works with sudo right now. The workaround is to run this to start Redis server as a daemon:

Cleaning up after PECL (optional)
By default, PECL plops a new extension='redis.so' line at the top of the main php.ini file. I prefer to move this line to its own extension file. These steps are optional, but it's more in line with how extensions should be loaded in modern php versions.

Remove the extension='redis.so' line that PECL added at the top of /usr/local/etc/php/7.4/php.ini.

Then create a file at /usr/local/etc/php/7.4/conf.d/ext-redis.ini with these contents:

After doing all of this, I'd recommend running valet restart. Enjoy developing Laravel apps on your new mac!

If you encounter any problems or have any thoughts about this process, reach out to me on Twitter, I'd love to hear about them!

Enjoy this article? Follow me on Twitter for more tips, articles and links.

I recently upgraded from Macbook Air 2017 to Macbook Pro with an M1 chip. My four year old Macbook Air was giving up. The performance to run heavy tasks like using the iOS simulator when developing and working on React Native apps was declining. I had long given up using the Android emulator and have been using a real Android device for testing. December 2020 was the time I decided its time to upgrade.

I had a long internal discussion with myself for almost a month that whether should I upgrade to M1 or stick with Intel-based chips and spend them bucks. Don't get me wrong here, M1 is not cheap either as I did go for a RAM upgrade to max limits which is currently 16GB in the base model. The kind of performance I was expecting after going through some online reviews and research, has been worth it so far (it is fast, no doubt). I received it two weeks back at the time of writing this post and since then I have installed all the necessary tools and utilities that help me work on Web development and React Native apps.

My local environment currently includes:

  • Rosetta 2
  • Homebrew
  • Git
  • Node.js
  • npm
  • Zsh
  • Oh My Zsh
  • iTerm
  • Xcode
  • yarn
  • VSCode Insiders Edition
  • Testing GatsbyJS builds

Other apps:

Brew M1
  • Google Chrome
  • Brave
  • Firefox Developer Edition
  • Android Studio
  • Insomnia as REST API client
  • And other desktop applications like Slack, Discord, Todoist, GitHub Desktop, and so on.

Rosetta 2

Rosetta 2 is the lifeline that allows you to run apps designed for Intel-based chips that use x86 architecture on ARM-based chips (in this case M1). This solution is provided by Apple in form of an emulator and doesn't come pre-installed. You have to install it manually. Fire up the Terminal application that comes pre-installed on the Big Sur and let your first command to execute be:

If you decide not to put the flag --agree-to-license, you will be prompted by Apple's interactive install and you will have to agree to their terms and license conditions in order to use it.

iTerm

My favorite terminal app that I have been using for years is iTerm. I am currently using two versions of iTerm on my setup. One with Rosetta 2 enabled and the default one. This way, I can only use the Rosetta 2 emulator when required. There are no performance issues I have found with using iTerm with Rosetta 2 for ARM-based applications.

If you'd like a similar setup, go to the Applications folder in your Macbook and duplicate the iTerm application.

You can rename the duplicated iTerm app. I have renamed it to iTerm_rosetta to differentiate between the two. Right-click the duplicated app and click Get Info. In the General check the box where it says Open using Rosetta.

Brew M1

Now, if you open the second terminal, it will be using Rosetta 2 emulator by default.

Other iTerm profile settings that I use:

Recently I started using Jetbrains Mono font.

For the overall looks and appearance, I use Dracula Pro Color Presets created by Zen Rocha.

And my last favorite thing is to split the working directory into two more different tabs using Command + D for horizontal panes. Make sure to have the following setting configured from General > Working Directory > select Advanced Configuration > click button Edit... > select Reuse previous session's directory under Working Directory for New Split Panes.

For terminal prompt, I use Spaceship ZSH.

Homebrew

On December 1, 2020, the Homebrew team made an official announcement on their website about the version release 2.6.0. The most significant changes among others they listed were the support for macOS Big Sur, using brew commands instead of brew cask and beginning to support macOS M1 and Apple Silicon or ARM-based chips.

This is the tricky part. At the time of writing this post, some formulae that you may like to use, might not work. It's better to track at the GitHub issue here in the Brew's official repository which is maintained by their team. I am thankful to the whole team behind the Homebrew for making it accessible and appreciate their hard work on making things work in such a short time.

Using the terminal, you can install the Homebrew by executing the default command:

Recently I found that it can be installed natively on a Macbook. You can run the above command in a native terminal environment as well without using the Rosetta terminal environment.

Git

I did install Git using brew command: brew install git.

To authenticate GitHub to be used from the terminal environment, I'd recommend you to check out the official document on creating and accessing personal tokens.

Xcode

After installing Git, for me, the next step is to install Xcode app from Apple's App Store.

After installing it, make sure to open it for the first time, from the menu bar, open Xcode > Preferences > Locations and make sure that Command Line Tools point towards the current Xcode app.

Node.js

On Apple's silicon-based laptops, Node.js versions starting from 14 and below are not supported. You will have to install version 15.x.x. or greater (depending on when you are reading this post).

At first, I installed Node.js using nvm without using Homebrew. Execute the below curl command to install nvm first:

After installing it, add the following to the .zshrc file and make sure to put them after sourcing Oh My Zsh:

To verify that nvm is installed, restart the console or the zsh session (execute: source .zshrc) and execute the following command to check out its current version:

Then run the command nvm install node.

Alternatively, you can also install the Node.js using the official installer for the current version which I later moved on to.

ZSH and Oh My Zsh

ZSH is the default shell that macOS Big Sur comes with. I like to use Oh My Zsh to manage ZSH configuration and some plugins and a theme to prettify the terminal.

To install, run the command below:

After installation, make sure that the file zshrc is exporting the below path:

The first I like to do after setting up the bare minimum ZSH configuration is to install a plugin called zsh-syntax-highlighting. It provides syntax highlighting for the ZSH shell. Execute the series below commands in the terminal window:

In a nutshell, this is my initial ZSH configuration in the file ~/.zshrc file:

After installing the syntax highlight plugin, it starts to recognize the commands:

VSCode

VSCode does not have native M1 support yet.

VSCode and VS Code Insiders edition both support ARM chips now (as of March, 13, 2021). Download the installer for Insiders edition from here and for VSCode here.

I am still using the same VSCode configuration from my previous setup:

Themes

I usually like to switch between a dark and a light theme.

  • For the dark theme where I spent most of my time, I am currently using morgan.codes-theme.
  • For the light version, I am using the theme called Quiet Light which comes pre-installed with a new VSCode installation.
  • For file icons, I love Material-Icon-Theme.
  • For terminal prompt, I use Spaceship ZSH.
  • Font: Jetbrains Mono font.

Brew M1 Status

Brew M1

Brew M1 Compatibility

Extensions

I use VSCode editor for both writing code and writing blog posts. Thus, the list of extensions below is the combination of extensions that fulfills both of my purposes.

Global NPM Packages I use

  • gatsby-cli To build and test out my personal blog built with Gatsby.
  • npm-check to check for outdated, incorrect, and unused dependencies.

For React Native Development

  • install [Watchman] to watch changes in the filesystem using the command: brew install watchman.
  • install Java Development Kit using the command: brew install --cask adoptopenjdk/openjdk/adoptopenjdk8.
  • install Android Studio

    • Then install Android SDK v29.

For more instructions on how to setup development environment for React Native, please follow the official documentation here.

Brew M1 Mac Install

For Gatsby Sites

If you have a side project that uses GatsbyJS, chances are you are going to face the issue https://github.com/lovell/sharp/issues/2460. Gatsby uses a C based library called Sharp that needs to be compiled under the ARM architecture. It did not work for me and the only way I could solve was to install vips formulae from Homebrew as mentioned in the GitHub issue itself.

Mac M1 Install Homebrew

Conclusion

That’s the setup I now use for my JavaScript, Node.js, React and React Native. I think it's a good machine. Hopefully, M1 is just the beginning of a new era of powerful computers for daily use.

Brew M1 Github

🤔 The only thing left for me is to find a way to transfer all laptop swag/stickers from my Macbook Air to Pro. I miss having them on this one.

Brew M1 Install

isapplesiliconready.com is another useful link I found sometime back to check what is compatible to work on Apple Silicon chips natively or using Rosetta or not optimized at all.





Comments are closed.