Rust安装并配置国内加速镜像源

7,755 阅读1分钟

安装Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • 测试
cargo --version

cargo 1.63.0 (fd9c4297c 2022-07-01)

Sample

  • 创建项目
cargo new hello-rust

hello-rust
├── Cargo.toml
└── src
    └── main.rs
  • 运行
cargo run

Compiling hello-rust v0.1.0 
  Finished dev [unoptimized + debuginfo] target(s) in 0.53s
   Running `target/debug/hello-rust`
Hello, world!

配置镜像

在执行cargo buildcargo run时,国内可能卡在Updating crates.io index, 配置文件一般在$HOME/.cargo/config(没有就创建一个),设置replace-with = 'ustc' or 'tuna'

[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"

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"