Skip to content

Instantly share code, notes, and snippets.

@Demwunz
Created January 28, 2020 21:45
Show Gist options
  • Save Demwunz/08922313a9e8cc95d9e0d57dafed2c12 to your computer and use it in GitHub Desktop.
Save Demwunz/08922313a9e8cc95d9e0d57dafed2c12 to your computer and use it in GitHub Desktop.
How to install Flutter on macOS using homebrew and asdf

How to install Flutter on macOS using homebrew and asdf

The official way to install the flutter and its dependencies is a mishmash of brew install, binary downloads alongside relying on system installed versions of ruby.

I became particularly frustrated when trying to setup flutter on macOS Mojave and macOS Catalina. I came across too many issues, and it took a lot of stackoverflow and google searches to overcome.

By using a package manager to install dependencies and runtimes, we can share the exact same setup in different environments and automate the install and escape the above issues.

This is particularly valuable if you use different machines, or have team members in different locations. Moreover, we know where everything belongs and how to upgrade or uninstall if necessary.

Until a complete homebrew approach is released, I think this is a decent step by step approach.

prerequisites

You need to make sure you have homebrew installed and also asdf to manage runtime dependencies.

If you don't have asdf installed already, you can follow my tutorial on how to install asdf

You should also install xcode via the mac app store. This could take a while depending on your download speed.

brew install dependencies

This will install the dependencies for flutter and asdf which we will use to install the runtimes.

We're installing:

  • asdf for our dart, flutter and ruby runtimes
  • android sdk for command line util sdkmanager
  • android studio to build flutter apps for android
  • intel haxm to help speed up flutter rendering
  • adoptopenjdk8 prebuilt java binary to make sure the above android stuff works
brew install asdf
brew install android-sdk
brew install android-studio
brew install haxm
brew cask install adoptopenjdk8

asdf runtimes

There are three steps for asdf, but this won't take long except depending on your download speed.

  1. Install the asdf plugins for dart, flutter and ruby
asdf plugin install dart https://github.com/patoconnor43/asdf-dart.git
asdf plugin install flutter
asdf plugin install ruby https://github.com/asdf-vm/asdf-ruby.git
  1. Install the actual runtimes
  • latest version of dart
  • latest stable version of flutter
  • We will use ruby 2.3.7 because it allows us to install cocoapods on macOS catalina.

You can use the latest version of Ruby if you like, but I've come across issues.

asdf install dart 2.7.0
asdf install flutter 1.12.13+hotfix.7-stable 
asdf install ruby 2.3.7
  1. Set the runtimes to global or local. You can set these to local if you have multiple projects that rely upon different versions.
asdf global dart 2.7.0
asdf global flutter 1.12.13+hotfix.7-stable 
asdf global ruby 2.3.7 

Cocoapods install on macOS Mojave and below

We don't need to use sudo we can install direct into the asdf ruby version.

gem install cocoapods

macOS catalina Cocoapods

The latest version of cocopads (1.8.4) doesn't respect the pod setup command on macOS catalina, so we have to use an older version until this bug is resolved.

gem install cocoapods -v 1.7.5

Install the cocoapods dependencies

pod setup

Install android studio plugins

You will need to install the flutter and dart plugins for android studio, otherwise flutter doctor will complain later on. Simply open up the app, go to configure > plugins and then install from the dialog as shown below. android studio plugins

Accept licences

We need to accept the licences for xcode in order to build ios apps

sudo xcodebuild -license

We need to accept the android licences in order to build our flutter app for android

flutter doctor --android-licenses

Run sdkmanager to make sure all dependencies are installed (depends on adoptopenjdk8 that we installed via brew)

sdkmanager

Export haxm and java paths

You might need to add these into your .zshrc or .bash_profile files if you get complaints about haxm or java.

export INTEL_HAXM_HOME=/usr/local/Caskroom/intel-haxm
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

Run flutter

Finally lets check our flutter install

flutter doctor -v

This is what you should see if all the above was done right.

flutter doctor

After completing all the above steps we now know that dart, flutter, ruby are all managed via asdf. The remaining dependencies are all installed via homebrew. Updates and upgrades should be straightforward, and we can document builds and releases to a particular setup.

Happy coding!

@Demwunz
Copy link
Author

Demwunz commented Aug 22, 2023

@jessica-d-pennell-at-xcelenergy I wrote this about three years ago, not sure if anything is still relevant anymore! Thanks for the feedback 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment