On Arch Linux there are two choices for installing rust.

  • Using pacman supported by Arch Linux

  • Using rustup officially supported by Rust

    pacman

    Install

Install the rustc compiler and Cargo

1
sudo pacman -S rust

Uninstall

1
sudo pacman -Rcns rust

rustup

Install

Download rustup and install rust.

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

Or download and review the rustup.sh script before installing

 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
88
89
90
❯ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh
❯ less ./rustup.sh
❯ sh ./rustup.sh
info: downloading installer

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:

  /home/xxx/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

  /home/xxx/.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:

  /home/xxx/.cargo/bin

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

  /home/xxx/.profile
  /home/xxx/.bash_profile
  /home/xxx/.bashrc
  /home/xxx/.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-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

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


>

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2022-06-30, rust version 1.62.0 (a8314ef7d 2022-06-27)
info: downloading component 'cargo'
  6.6 MiB /   6.6 MiB (100 %)   5.0 MiB/s in  1s ETA:  0s
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %)   6.1 MiB/s in  3s ETA:  0s
info: downloading component 'rust-std'
 26.0 MiB /  26.0 MiB (100 %)   4.7 MiB/s in  5s ETA:  0s
info: downloading component 'rustc'
 54.1 MiB /  54.1 MiB (100 %)   5.7 MiB/s in 11s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.3 MiB /  18.3 MiB (100 %)  10.2 MiB/s in  1s ETA:  0s
info: installing component 'rust-std'
 26.0 MiB /  26.0 MiB (100 %)  14.9 MiB/s in  1s ETA:  0s
info: installing component 'rustc'
 54.1 MiB /  54.1 MiB (100 %)  17.3 MiB/s in  3s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - rustc 1.62.0 (a8314ef7d 2022-06-27)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

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

rustup, rustup toolchain manager, is for the purpose of developing software. By using rustup we can install multiple toolchains (stable, beta, nightly) for multiple targets (windows, mac, android) and architectures (x86, x86_64, arm).

Uninstall

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
❯ rustup self uninstall


Thanks for hacking in Rust!

This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.

Continue? (y/N) y

info: removing rustup home
info: removing cargo home
info: removing rustup binaries
info: rustup is uninstalled

Important directories

  • Rustup root directory, ~/.rustup, can be set by the env varaiable RUSTUP_HOME

  • Cargo root directory, ~/.cargo, can be set by the env variable CARGO_HOME

  • Cargo bin directory, ~/.cargo, includes executable tools, like cargo, rustup. We need to include the path in the env variable PATH.

Mirrors

Read more on rust Environment variables

1
2
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
  • Setup crates.io mirror in config file ~/.cargo/config (create it if not exist)

1
2
3
4
5
6
# ~/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

Ref