[asdf Rust] Use asdf rust plugin to install multiple Rust versions

asdf and Rust 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 …

Rust is a language empowering everyone to build reliable and efficient software.

This article is about how to use asdf and Rust plugin to install multiple Rust 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 Rust Plugin

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

# Install Rust plugin
$ asdf plugin-add rust https://github.com/code-lever/asdf-rust.git

List all Rust Version

Update Rust plugin.

1
$ asdf plugin update rust

List all Rust versions.

1
$ asdf list all rust

Install Rust version

Install a Rust version manually.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ asdf install rust 1.50.0

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

$ echo "rust 1.50.0" >> ~/.tool-versions

$ asdf exec rustup --version
rustup 1.23.1 (3df2264a9 2020-11-30)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.48.0 (7eac88abb 2020-11-16)

$ asdf exec rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)

Or install another version.

1
$ asdf install rust 1.49.0

Install rust-src

The source for Rust’s standard library can be obtained by running rustup component add rust-src. It will be downloaded to the <toolchain root>/lib/rustlib/src/rust directory of the current toolchain.

1
$ rustup component add rust-src

See Can rustup download the Rust source code? | FAQ - The rustup book - https://rust-lang.github.io/rustup/faq.html#can-rustup-download-the-rust-source-code to learn more.

References

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

[2] GitHub - code-lever/asdf-rust: Rust plugin for the asdf version manager - https://github.com/code-lever/asdf-rust

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

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