[Dart] Use asdf dart plugin to install multiple Dart versions

asdf and Dart Plugin

asdf is a single CLI tool for managing multiple runtime versions. It extend with a simple plugin system to install your favourite language: Dart, Elixir, Flutter, Golang (Go), Java, Node.js, Python, Ruby …

This article is about how to use asdf and Dart plugin to install multiple Dart versions on macOS with the Homebrew package manager.

Prerequisites

  • Xcode Command Line Tools
    The Xcode Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in macOS which is consists of the macOS SDK and command-line tools such as Clang, which are installed at this

    For more information about installing and using Xcode Command Line Tools, see the Xcode Command Line Tools

  • Homebrew
    Homebrew is the Missing Package Manager for macOS (or Linux).

    For more information about installing and using Homebrew, see the Homebrew - https://brew.sh/.

Installation

Install asdf

1
2
3
4
5
# Install asdf dependencies
$ brew install coreutils curl git

# Install asdf
$ brew install asdf

asdf Dart Plugin

1
2
3
4
5
# Install Dart plugin requirements
$ brew install openssl readline

# Install Dart plugin
$ asdf plugin-add dart https://github.com/patoconnor43/asdf-dart.git

List all Dart Version

Update Dart plugin.

1
$ asdf plugin update dart

List all Dart versions.

1
$ asdf list all dart

Install Dart version

Install a Dart version manually.

1
2
3
4
5
6
7
8
9
10
11
$ asdf install dart 2.12.0

$ dart --version
No version set for command dart
Consider adding one of the following versions in your config file at ~/.tool-versions
dart 2.12.0

$ echo "dart 2.12.0" >> ~/.tool-versions

$ asdf exec dart --version
Dart SDK version: 2.12.0 (stable) (Thu Feb 25 19:50:53 2021 +0100) on "macos_x64"

Or install another version.

1
$ asdf install dart 2.10.0

References

[1] Manage asdf - https://asdf-vm.com/#/core-manage-asdf

[2] PatOConnor43/asdf-dart: dart plugin for asdf version manager https://github.com/asdf-vm/asdf - https://github.com/PatOConnor43/asdf-dart

[3] Home · rbenv/dart-build Wiki - https://github.com/rbenv/dart-build/wiki#suggested-build-environment

[4] Homebrew - https://brew.sh/

[5] Dart programming language | Dart - https://dart.dev/