Rust安装

70 阅读1分钟

参考

rsproxy.cn/

设置环境变量

建议将以下操作追加到 ~/.bashrc~/.zshrc 中使其永久生效

  • 设置下载镜像
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
  • 设置安装路径
export CARGO_HOME=$HOME/.cargo # 自定义cargo安装路径,后续使用cargo install安装的工具会在该目录下,默认为 $HOME/.cargo
export RUSTUP_HOME=$HOME/.rustup # 自定义rustup安装路径,默认为 $HOME/.cargo

安装

  • 在保证以上环境变量生效的前提下,执行以下命令
curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh

配置 crate.io 镜像及其他(可选)

  • 编辑 $CARGO_HOME/config.toml 文件
# 配置 crate.io 镜像
[source.crates-io]  
replace-with = 'rsproxy-sparse'  
[source.rsproxy]  
registry = "https://rsproxy.cn/crates.io-index"  
[source.rsproxy-sparse]  
registry = "sparse+https://rsproxy.cn/index/"  
[registries.rsproxy]  
index = "https://rsproxy.cn/crates.io-index"  
[net]  
git-fetch-with-cli = true  

# 设置项目的构建目录,统一在 $CARGO_HOME 同级目录的 target 目录下,方便清理
[build]  
target-dir="target"