00 配置Rust开发环境
概要: 在macOS上,配置Rust开发环境
创建时间: 2023.03.09 00:38:18
更新时间: 2023.11.13 23:25:17
安装Rust
适用于 macOS 或 Linux 系统
Bash |
---|
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
更新Rust

如果rustup update
命令较慢,国内可通过配置镜像进行加速:
将下面两行环境变量写入到系统中,即写入到 zsh 环境的 ~/.zshrc
或者 bash 环境的 ~/.bashrc
中
Bash |
---|
| export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
|
其他环境变量
Bash |
---|
| # 更改 Cargo 的默认位置
export CARGO_HOME=/path/to/your/directory
# 更改编译输出的位置
export CARGO_TARGET_DIR=/path/to/your/build/directory
|
卸载Rust
配置Rust
考虑到国内网络环境,为加速以后的包下载等工作,需要编辑 ~/.cargo/config
文件,使用国内源
Properties |
---|
| # 配置镜像源
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
# 指定镜像
replace-with = 'rsproxy' # 或者使用 tuna, ustc, sjtu 之一即可
# 字节跳动镜像
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
# 稀疏索引,要求 cargo >= 1.68
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
# -----------------------------------------------
# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
# -----------------------------------------------
# 配置代理
# [http]
# proxy = "xxx"
# [https]
# proxy = "xxx"
|
Rust工具链

在上述工具中
cargo
是Rust的构建工具和包管理器
rustdoc
可以直接在本地浏览器页面打开Rust文档
rustfmt
是Rust语言的默认格式化工具
rustup
是Rust工具链安装器
参考