Setting up Dart for local development

I've been learning Flutter for mobile development lately. I like the journey so far and I'm going to be posting stuff I learn along the way. First i'll show how to setup Dart for local development. I use asdf for managing different versions of language runtimes on my local machine. I found out about it when trying to setup different Python versions. My dev machine comes with Python 3.7 but at work we use Python 3.6 and I like having the exact version in use. What to do? asdf to the rescue. asdf has a plugin system that allows allows the installation of different langauge runtimes for example you can install Python 3.5, 3.6 and 3.8 on the same machine and switch between them. A lot of langauges are supported you can find these here.

To setup asdf run:

1
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.2`

Replace 0.7.2 with the latest version which you can find here. Next add asdf to your shell like so:

1
2
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.zshrc
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc

Remember to replace .zshrc with your shell specific config file e.g .bashrc. Reload your config file source .zshrc. You are good to go.

Now lets setup dart. We begin by installing the dart plugin:

1
asdf plugin-add dart

Now we can install dart sdk and tools by running:

1
asdf install dart 2.3.1

Replace 3.2.1 with the latest version or the version you want. You can find these here. You need to choose a global version. This is the version that will be run when you type dart in any shell. You can do this by:

1
asdf global dart 2.3.1

You can also set a version to be used only in the current shell:

1
asdf local dart 2.3.1

Happy darting.