惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
罗磊的独立博客
博客园 - 司徒正美
Last Week in AI
Last Week in AI
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
B
Blog
博客园 - 【当耐特】
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell

Impath's Isle

抛物线 Ⅱ | Impath 砚西记·旸 | Impath Windows 下 Gram 编辑器折腾记录 | Impath 砚西记·衡 | Impath 抛物线 | Impath's Isle 宜兴社会实践游记 | Impath's Isle 砚西记·博徒 | Impath's Isle 砚西记·序 | Impath's Isle 写在丙午马年之前 | Impath's Isle 砚西记·曙 | Impath's Isle 笔记:左手双金定则 | Impath's Isle 江南大学社会实践琐记 | Impath's Isle LNMP 环境下 Typecho 后台 404 的一般解决方案 | Impath's Isle mdBook:使用 Pandoc 快速创建高质量 PDF 电子书 | Impath's Isle 使用 MSYS2 部署 Windows 下 GCC 开发环境 | Impath's Isle 二 | Impath 砚西记·志涵 | Impath's Isle 砚西记·鹏钧 | Impath's Isle 砚西记·邹昱 | Impath's Isle 一 | Impath 2025 春学期研究性学习项目大纲 | Impath's Isle 2024 秋学期研究性学习总结 | Impath 无锡市业余无线电入门指北(旧版) | Impath's Isle
Windows 下 Rust 开发环境部署:GNU 工具链及镜像优化 | Impa...
Impath · 2025-07-19 · via Impath's Isle

前言

前几日,我在新系统上重新部署 Rust 开发环境,又折腾了一番,特此记录。

前置环境

因为不想碰太臃肿的 MSVC ,但是 Rust requires a linker and Windows API libraries ,因此本文采用 GNU 工具链代替 MSVC。

前置准备

下载对应版本的 rustup-init.exe

rustup & cargo 安装路径

如需自定义安装路径,请预先设置以下环境变量:

变量名变量值(默认)
RUSTUP_HOMEC:\Users\User\.rustup
CARGO_HOMEC:\Users\User\.cargo

配置 rustup 下载镜像

更改下载镜像可以大幅提升安装文件下载速度(毕竟文件服务器在海外,速度不稳定是很正常的)。

添加环境变量,变量名为:

RUSTUP_DIST_SERVER

变量值为(示例,使用清华源):

https://mirrors.tuna.tsinghua.edu.cn/rustup

安装 rustup

双击 rustup-init.exe 安装,在跳出的控制台窗口中一般会显示:

Rust Visual C++ prerequisites

Rust requires a linker and Windows API libraries but they don't seem to be
available.

These components can be acquired through a Visual Studio installer.

1) Quick install via the Visual Studio Community installer
   (free for individuals, academic uses, and open source).

2) Manually install the prerequisites
   (for enterprise and advanced users).

3) Don't install the prerequisites
   (if you're targeting the GNU ABI).

输入3 并回车,即跳过 MSVC 安装。

随后显示:

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:

  C:\Users\Administrator\.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  C:\Users\Administrator\.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:

  C:\Users\Administrator\.cargo\bin

This path will then be added to your PATH environment variable by
modifying the PATH registry key at HKEY_CURRENT_USER\Environment.

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation

确认安装路径无误后,直接回车(选择默认选项 1)。安装完成后将看到:

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload its PATH environment variable to include
Cargo's bin directory (%USERPROFILE%\.cargo\bin).

Press the Enter key to continue.

此时 rustup 安装完成。

打开新的 CMD,运行:

rustc --version

若输出版本号,说明安装成功。

更改 cargo 镜像源

%CARGO_HOME% 目录下新建或编辑 config.toml,内容如下(参考自:https://www.cnblogs.com/-CO-/p/18041169):

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
 
# 具体使用的源
replace-with = 'tuna'
 
## 配置多个源地址
# rsproxy
[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"
 
# 阿里源
[source.aliyun]
registry = "sparse+https://mirrors.aliyun.com/crates.io-index/" 
 
# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
 
# 中国科学技术大学
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index/"
 
# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
 
# rustcc社区
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
 
[net]
git-fetch-with-cli=true

配置工具链

  1. 查看可用工具链:
rustup target list
  1. 切换到 GNU 工具链:
rustup default stable-x86_64-pc-windows-gnu

至此,Rust + GNU 环境配置完毕。