Installing Flutter SDK via Snap or Brew
Dec 30, 2021
Ubuntu is the most popular desktop Linux distribution, especially if we count all of its derivative Linux distributions. The relationship between Ubuntu and Flutter is growing closer: the Ubuntu operating system installer got implemented in Flutter lately. Another change in recent Ubuntu versions is that the built-in software store is based on SnapCraft, and users pick and install snaps rather than Debian packages via apt.
This use of Snap circles back to Flutter: currently the primary advised installation method of the Flutter SDK on Linux is via snap. Snap has a package dependency on systemd, and since I use a systemd-less Debian flavor called Devuan, I had to take the secondary route: install Flutter SDK manually. Manual installation is almost as simple as the snap method. Essentially, you clone the Flutter SDK GitHub repository, and flutter upgrade pulls the latest changes and kicks off compilation and companion tasks based on the refreshed source.
Systemd has penetrated the whole Linux ecosystem: on one side there is Debian and its biggest derivative Ubuntu (and a whole bunch of Ubuntu derivatives), and on the other side, the Fedora / RedHat-based derivative family tree. The latter distribution tree is not a surprise because systemd originates from Lennart Poettering, who is a software engineer at RedHat and a long-time Linux contributor. Even if someone is not using Ubuntu, snap is available as a native package and, with that, we create an extra layer of package distribution ecosystem above the operating system’s native package management (native package management uses deb packages with apt / dpkg on Debian and rpm packages with yum or dnf on Fedora/RedHat). A big advantage of snaps is that you won’t hit any dependency roadblocks because snaps are self-contained. You can also easily switch between various versions of software or SDKs. Although the manual installation of Flutter is easy, nothing can be easier than installation with literally just one click or command.
At the same time, Flutter has a very low-friction and awesome CLI. Developers can extremely easily get information on the health of their Flutter installation (flutter doctor), upgrade to the latest version (flutter upgrade), or switch between stable / beta / nightly distribution channels. The question arises: once someone has installed Flutter via snap or brew, how should it be kept updated? On one hand, various IDEs (Integrated Development Environments) like Android Studio or Visual Studio Code will check from time to time and warn if a newer Flutter version is available. These tools use the Flutter CLI underneath and would promote a flutter upgrade. However, Snap as a package distribution ecosystem also supposedly has new versions of the SDK from time to time and warns about them through its native notification channels.
The same question arises on macOS environments too. The official Flutter documentation only outlines the manual installation on OSX; however, I can guarantee that every developer already has the Homebrew alternative package management system on their machine. Therefore, several developers simply install Flutter via brew because they see it being available there and it’s a one-click install just like in the case of snap. Brew is very up to date, and it already offers the 2.8.1 stable Flutter version, which came out almost two weeks ago. A fellow developer was not able to simply upgrade to that package, though, so some force was needed via brew upgrade –greedy. Also, see this or this.
The rule of thumb is—and this is why I’m writing this post—that Snapcraft- or Homebrew-based installation methods only provide an installation vehicle. Every developer should provision their Flutter SDK via CLI commands (or the IDE, which does the same). When Snap or Brew says there’s a newer version available, don’t fall for that and stick with the CLI.
The Flutter SDK GitHub repository almost certainly provides the most up-to-date version, while Snap and Brew packages may follow changes with some lag—or sometimes significant lag. But that’s fine because the installation step is immediately followed by flutter doctor, which should guide the developer toward an immediate update if needed.
The package version in Snap can lag by design: in an unrelated issue in October I realized that a fellow Linux user-installed Flutter from snap and Snapcraft at that time had a very old package (built in August) offering an even older SDK version (2.2.1 is a version from May). The Linux user thought that after the snap install, he would have the latest version. After raising two issues in the Flutter GitHub repository (see Flutter Snap package is extremely outdated #93495 and Snap builds are not triggered for several months now #93497), it turned out that the CI/CD (Continuous Integration / Continuous Delivery) pipeline had a mechanism to build snap package artifacts, but that went silent after some storage bucket changes. That issue was resolved and there was a new Snap build on November 15th as a result. I opened a regression ticket as well (Snap package version is lagging behind #95989), and I was also directed to the Canonical Snap repository, where I got a clear signal that the CLI is the way to update.
Then I realized that even if the snap packages were semi-up-to-date, that could still pose a mixed signal, and it would be good to have a clear policy on how someone is supposed to keep the Flutter SDK installation up-to-date. Unfortunately, the package manager can interfere and may advise overriding a fresher local state with an older version. These are not infrastructure issues but rather documentation issues, so I opened tickets about the Linux installation (PAGE ISSUE: Linux install #6460) and declaring the policy on upgrade when installing from a side-channel (PAGE ISSUE: Declare clear upgrade policy when installing the SDK via snap on Linux #6499).
Edit (April 26, 2022): the extra package manager layer can not only advise overriding the current (and potentially newer) install, but on some distributions, snaps could upgrade automatically. That can be a problem, so watch out!