问题现状
由于rustup官方服务器在国外,如果直接按照rust官网的安装方式安装非常容易失败,用国内的镜像则可以很快搞定。
官方安装
文档: Install Rust - Rust Programming Language
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
国内镜像安装
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
bash 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/leo/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory located at:
/home/leo/.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/leo/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/home/leo/.profile
/home/leo/.bash_profile
/home/leo/.bashrc
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
>1
下载完成后
stable-x86_64-unknown-linux-gnu installed - rustc 1.56.1 (59eed8a2a 2021-11-01)
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
最后执行提示的source命令完成安装
配置cargo源
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
将上述内容写到~/.cargo/config文件中