How to install Flutter on macOS using homebrew and asdf
Tags: flutter, productivity, opensource, tutorial
Published: 2020-01-28 19:24:40

---
title: How to install Flutter on macOS using homebrew and asdf
published: true
description: How to install Flutter on macOS using homebrew and asdf
tags: flutter, productivity, opensource, tutorial 
cover_image: https://i.imgur.com/aNGfrm8.png
series: code productivity
---

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](https://brew.sh) installed and also [asdf](https://asdf-vm.com) to manage runtime dependencies.

If you don't have asdf installed already, you can [follow my tutorial on how to install asdf](https://dev.to/0xdonut/manage-your-runtime-environments-using-asdf-and-not-nvm-or-rvm-etc-2c7c)

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](https://developer.android.com/studio) to build flutter apps for android
 - [intel haxm](https://github.com/intel/haxm) to help speed up flutter rendering
 - [adoptopenjdk8](https://adoptopenjdk.net/) 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](https://flutter.dev/docs/development/tools/sdk/releases?tab=macos)
- 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.
![android studio plugins](https://i.imgur.com/gw71ERm.png)

## 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](https://i.imgur.com/aRufIrt.png)

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!