How to install Flutter on macOS using homebrew and asdf
Mr F.

Mr F. @0xdonut

About: 0010

Joined:
Dec 24, 2017

How to install Flutter on macOS using homebrew and asdf

Publish Date: Jan 28 '20
30 19

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
Enter fullscreen mode Exit fullscreen mode

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-add flutter
asdf plugin install ruby https://github.com/asdf-vm/asdf-ruby.git
Enter fullscreen mode Exit fullscreen mode

2) 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
Enter fullscreen mode Exit fullscreen mode

3) 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 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Install the cocoapods dependencies

pod setup
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

flutter doctor --android-licenses
Enter fullscreen mode Exit fullscreen mode

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

sdkmanager
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

Run flutter

Finally lets check our flutter install

flutter doctor -v
Enter fullscreen mode Exit fullscreen mode

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!

Comments 19 total

  • akarsh
    akarshFeb 11, 2020

    @0xdonut

    You need to change the adding of flutter plugin
    from
    asdf plugin install flutter
    to this
    asdf plugin-add flutter
    I faced installation issue and i had search the PR of asdf plugins to know how flutter is added - github.com/asdf-vm/asdf-plugins/pu... and this is plugin repo - github.com/oae/asdf-flutter where installation step is changed.

    Good tutorial. Thanks for writing as I was looking to install runtimes using version manager.

    • Mr F.
      Mr F.Feb 12, 2020

      Thanks for pointing that out, it worked for me, but I'll update for anyone else who may find issues

    • Michael Riecken
      Michael RieckenFeb 24, 2020

      Agreed, @akarsh - the same happened for me and the same solution solved it.

  • Michael Riecken
    Michael RieckenFeb 24, 2020

    I had an issue with sdkmanager and had to explicitly point to the Java 8 install directory by adding this line to the beginning of /usr/local/bin/sdkmanager

    JAVA_HOME=/System/Volumes/Data/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
    

    sdkmanager requires Java 8 (or some xml libraries properly linked). This should hook you up with Java 8 for the run of sdkmanager, but not set it universally through your mac.

    • Mr F.
      Mr F.Mar 12, 2020

      didn't this work for you?

      export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
      
  • Rom
    RomMar 4, 2020

    How much do you like your flutter experience so far? I'd be glad to read more about it.

    • Mr F.
      Mr F.Mar 5, 2020

      I've enjoyed it so far. I think there is stigma around dart as a programming language and many developers wont let go of react.

      Technologies come and go. I just try to choose the best tool for the job, that allows me to get on with my job!

      I'm still very much learning about the flutter ecosystem

  • akarsh
    akarshMar 7, 2020

    @0xdonut

    Suggestion to add the location of Flutter SDK location in the guide.

    At the end of the guide, you can add about how to find the location of Flutter SDK on macOS. I had to spend some time and search on the internet to know where asdf installs the plugins. If you want to start a flutter project in Android Studio you need to manually give the Flutter SDK location. I added the steps to find the location to this StackOverflow question - stackoverflow.com/a/60575597/1334228

    • Mr F.
      Mr F.Mar 12, 2020

      Hmm that's odd.

      You can find which flutter versions you have by doing

      $ asdf list flutter
      > 1.12.13+hotfix.7-stable
      

      to get the path you just need to do

      $ which flutter
       >  /Users/0xDonut/.asdf/shims/flutter
      

      you can use this output to inform android studio

      • Jay
        JayMar 31, 2020

        This didn't work for me- ~/.asdf/shims/flutter is the executable, whereas Android Studio wants the directory. This is a problem for the Dart plugin too.

        I can use ~/.asdf/installs/flutter/<version>, but now I'm not honoring asdf's global selection (or its local one if .tool-versions is in the project).

        (btw thanks for the write up!)

    • PranitSh
      PranitShMay 30, 2020

      I asked the people that made the flutter plugin and they helped me out. For making flutter work with your IDE (haven't done this in Android but have in VScodium or Vscode). Answer On Stack

      In command line:
      asdf where flutter

      In a text document:
      export FLUTTER_ROOT="$/asdf/where/flutter/should/go/here"

      Add that to your bash_profile above the asdf part. Or your asdf installation won't work.
      With nano, ctrl o, enter, ctrl x.

      Give your IDE the path to the installation of asdf where flutter (I accidentally gave it the path to the shim, it didn't worked but I restarted my computer and it did). So, if it didn't work, the change needs to take effect, restart your computer.

  • Stephen Charles Huey
    Stephen Charles HueyMay 22, 2020

    Thanks for a detailed write-up! Do you know if the problem with Cocoapods is still an issue with Flutter on Catalina? Is it still necessary to install an old version?

    • Mr F.
      Mr F.May 23, 2020

      Thanks for reading it :)

      I haven't looked into it in a while, but I guess the easiest way is to run $ gem install cocoapods and then do $ pod install, if you get errors relating to pods not being installed, then you can simply uninstall and follow my instruction and it should all work.

  • PranitSh
    PranitShMay 23, 2020

    brew tap AdoptOpenJDK/openjdk

    This makes brew cask install openjdk8 work.

    • Mr F.
      Mr F.May 23, 2020

      Thanks, I'll add that to the instructions

      • ppshah2023
        ppshah2023May 25, 2020

        Wait, I also did brew crack install for every install command. It resulted in the same thing at the end but there was one issue, I have to use the terminal to create and use flutter commands as I can’t get vscodium to accept the flutter install location. I have to rename the flutter install package that asdf uses (which is 17.1-stable I believe) to flutter for vscodium to use it and add it to path. and then asdf can’t find it, it seems that the only way to integrate a flutter installation in vscodium is to go through the flutter website, or creating tons of command line shortcuts that change the vscodium layout, which is very annoying as I can’t get it to work. Or I would share

  • Paul Hammant
    Paul HammantJul 20, 2020

    asdf plugin add has replaced asdf plugin install

    brew install intel-haxm is replaces haxm now, and more things are casks in July2020

  • Vivian Farrell
    Vivian FarrellSep 18, 2020

    Why does everyone seem to use brew install when I have to use brew cask install?

  • Emanuel937
    Emanuel937Jul 25, 2021

    just run : brew install flutter
    then: flutter doctor

Add comment