Rust使用国内源加速在线安装开发环境搭建

环境

rust: 1.83.0(2024-11-26)

1. Rustup下载器在线安装

windows:

https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe

unix:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

2. 配置环境变量

windows:

set RUSTUP_DIST_SERVER=https://rsproxy.cn
set RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup

unix:

export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"

3. 在线加速安装

./rustup-init

默认安装即可

4. Rust命令行

  • 查看rust版本
rustc -V
rustc 1.83.0 (90b35a623 2024-11-26)
  • 新建rust项目
cargo new hello_world
  • cargo编译rust项目
$ cargo build
  • rustc编译rust项目
$ rustc src/main.rs
  • 运行rust程序
$ ./target/debug/hello_world
Hello, world!

5. IDE集成开发环境

5.1 VSCode

Rust with Visual Studio Code

5.2 vs2022

User Manual

6. 使用镜像加速cargo

$CARGO_HOME/config中加入如下内容

[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:在 Windows 系统默认为:%USERPROFILE%\.cargo,在类 Unix 系统默认为:$HOME/.cargo


Reference:

  1. Other Installation Methods - Rust Forge (rust-lang.org)
  2. https://rsproxy.cn/
Logo

一站式 AI 云服务平台

更多推荐