Rustup

Rustup 是 Rust 官方的跨平台 Rust 安装工具。

镜像站只会保留一段时间的 nightly,如果在安装时出现错误,请用 RUSTUP_DIST_SERVER= rustup ... 来使用官方源。

使用 rustup 安装 rust 时,若要启用镜像源,执行:

  • 对 Linux/macOS 用户:
# for bash
RUSTUP_DIST_SERVER=https://mirrors.ha.edu.cn/rustup rustup install stable # for stable
# for fish
env RUSTUP_DIST_SERVER=https://mirrors.ha.edu.cn/rustup rustup install stable # for stable
# for bash
RUSTUP_DIST_SERVER=https://mirrors.ha.edu.cn/rustup rustup install nightly # for nightly
# for fish
env RUSTUP_DIST_SERVER=https://mirrors.ha.edu.cn/rustup rustup install nightly # for nightly
# for bash
RUSTUP_DIST_SERVER=https://mirrors.ha.edu.cn/rustup rustup install nightly-YYYY-mm-dd
# for fish
env RUSTUP_DIST_SERVER=https://mirrors.ha.edu.cn/rustup rustup install nightly-YYYY-mm-dd
  • 对 Windows,PowerShell 下:
# for powershell
$env:RUSTUP_DIST_SERVER="https://mirrors.ha.edu.cn/rustup"
rustup install stable # for stable
rustup install nightly # for nightly
rustup install nightly-YYYY-mm-dd

若要长期启用镜像源,执行:

  • 对 Linux/macOS 用户:
# for bash
echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.ha.edu.cn/rustup/rustup' >> ~/.bashrc
echo 'export RUSTUP_DIST_SERVER=https://mirrors.ha.edu.cn/rustup' >> ~/.bashrc
# for fish
echo 'set -x RUSTUP_UPDATE_ROOT https://mirrors.ha.edu.cn/rustup/rustup' >> ~/.config/fish/config.fish
echo 'set -x RUSTUP_DIST_SERVER https://mirrors.ha.edu.cn/rustup' >> ~/.config/fish/config.fish
  • 对 Windows,PowerShell 下:
# for powershell
'$env:RUSTUP_UPDATE_ROOT="https://mirrors.ha.edu.cn/rustup/rustup"' >> $profile
'$env:RUSTUP_DIST_SERVER="https://mirrors.ha.edu.cn/rustup"' >> $profile

注:rustup 在判断是否需要更新时依赖于 toml 的 sha256,由于 toml 内容中相关链接被替换为镜像源,第一次切换到镜像源时各个 channel 会被认为需要更新。