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
andruby
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-add flutter
asdf plugin install ruby https://github.com/asdf-vm/asdf-ruby.git
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
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
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.
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.
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!
Top comments (19)
asdf plugin add
has replacedasdf plugin install
brew install intel-haxm
is replaces haxm now, and more things are casks in July2020@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.
Thanks for pointing that out, it worked for me, but I'll update for anyone else who may find issues
Agreed, @akarsh - the same happened for me and the same solution solved it.
@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
Hmm that's odd.
You can find which flutter versions you have by doing
to get the path you just need to do
you can use this output to inform android studio
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!)
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.
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
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.
didn't this work for you?
How much do you like your flutter experience so far? I'd be glad to read more about it.
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
Why does everyone seem to use
brew install
when I have to usebrew cask install
?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?
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.just run : brew install flutter
then: flutter doctor
brew tap AdoptOpenJDK/openjdk
This makes brew cask install openjdk8 work.
Thanks, I'll add that to the instructions
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