[Rust] How to install rustup and Rust on macOS

rustup.rs - The Rust toolchain installer

rustup.rs - The Rust toolchain installer - https://rustup.rs/ is an installer for
the systems programming language Rust and support multiple Rust versions.

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

Installation

There are two ways to install rustup and Rust on macOS.

Install by curl and shell

To download Rustup and install Rust, run the following in your terminal, then follow the on-screen instructions.

1
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install by Brew

First install Brew Formula rustup-init.

1
$ brew install rustup-init

Then, initiate rustup.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
$ rustup-init
Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

/Users/cloudolife/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

/Users/cloudolife/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

/Users/cloudolife/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

/Users/cloudolife/.profile
/Users/cloudolife/.bash_profile
/Users/cloudolife/.bashrc
/Users/cloudolife/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


default host triple: x86_64-apple-darwin
default toolchain: stable (default)
profile: default
modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

info: profile set to 'default'
info: default host triple is x86_64-apple-darwin
info: syncing channel updates for 'stable-x86_64-apple-darwin'
619.5 KiB / 619.5 KiB (100 %) 84.4 KiB/s in 8s ETA: 0s
info: latest update on 2020-11-19, rust version 1.48.0 (7eac88abb 2020-11-16)
info: downloading component 'cargo'
4.0 MiB / 4.0 MiB (100 %) 664.2 KiB/s in 6s ETA: 0s
info: downloading component 'clippy'
1.7 MiB / 1.7 MiB (100 %) 1.6 MiB/s in 1s ETA: 0s
info: downloading component 'rust-docs'
13.3 MiB / 13.3 MiB (100 %) 2.5 MiB/s in 6s ETA: 0s
info: downloading component 'rust-std'
20.4 MiB / 20.4 MiB (100 %) 2.1 MiB/s in 9s ETA: 0s
info: downloading component 'rustc'
49.9 MiB / 49.9 MiB (100 %) 1.7 MiB/s in 52s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: using up to 500.0 MiB of RAM to unpack components
info: installing component 'clippy'
info: installing component 'rust-docs'
13.3 MiB / 13.3 MiB (100 %) 6.1 MiB/s in 2s ETA: 0s
info: installing component 'rust-std'
20.4 MiB / 20.4 MiB (100 %) 12.1 MiB/s in 1s ETA: 0s
info: installing component 'rustc'
49.9 MiB / 49.9 MiB (100 %) 12.3 MiB/s in 4s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-apple-darwin'

stable-x86_64-apple-darwin installed - rustc 1.48.0 (7eac88abb 2020-11-16)


Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done
automatically.

To configure your current shell, run:
source $HOME/.cargo/env

Reload environment.

1
$ source $HOME/.cargo/env

Common Commands

n the Rust development environment, all tools are installed to the ~/.cargo/bin directory, and this is where you will find the Rust toolchain, including rustc, cargo, and rustup.

Check Version

Check rustc version.

1
2
$ rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)

Check cargo version.

1
2
$ cargo --version
cargo 1.48.0 (65cbdd2dc 2020-10-14)

check rustup version

1
2
3
4
$ rustup --version
rustup 1.23.1 (2020-12-03)
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)`

Updage Rust

1
$ rustup update

Uninstall Rust.

1
$ rustup self uninstall

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] rustup.rs - The Rust toolchain installer - https://rustup.rs/

[2] Install Rust - Rust Programming Language - https://www.rust-lang.org/tools/install

[3] Rust Programming Language - https://www.rust-lang.org/

[4] rustup-init — Homebrew Formulae - https://formulae.brew.sh/formula/rustup-init