记录一次rust的安装-Windows 10

下载rust

到rust官网下载rustup: https://www.rust-lang.org/tools/install

rustup是一个管理 Rust 版本和相关工具的命令行工具。下载时需要联网。

运行以后提示需要安装C++ build tools, 是否继续:

Rust Visual C++ prerequisites

Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
later, but they don't seem to be installed.

The easiest way to acquire the build tools is by installing Microsoft
Visual C++ Build Tools 2019 which provides just the Visual C++ build
tools:

  https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

Please ensure the Windows 10 SDK and the English language pack components
are included when installing the Visual C++ Build Tools.

Alternately, you can install Visual Studio 2019, Visual Studio 2017,
Visual Studio 2015, or Visual Studio 2013 and during install select
the "C++ tools":

  https://visualstudio.microsoft.com/downloads/

Install the C++ build tools before proceeding.

If you will be targeting the GNU ABI or otherwise know what you are
doing then it is fine to continue installation without the build
tools, but otherwise, install the C++ build tools before proceeding.

Continue? (Y/n)

这里选择否退出。

安装Visual c++ 生成工具

, 去提示的地址https://visualstudio.microsoft.com/downloads/安装Visual Studio 2019 生成工具。
Visual Studio 2019 工具下拉菜单里选择Visual Studio 2019 生成工具并下载, 之后安装。

安装时在工作负载中勾选c++生成工具, 在语言包中勾选英语, 开始安装。

安装完之后重启。

安装rust

重新打开rustup-init.exe:

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to
Cargo's bin directory, located at:

  C:\Users\windows\.cargo\bin

This can be modified with the CARGO_HOME environment variable.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  C:\Users\windows\.rustup

This can be modified with the RUSTUP_HOME environment variable.

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

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
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

这里选择第一个, 或者直接按回车, 出现安装成功提示:

Rust is installed now. Great!

To get started you need Cargo's bin directory (%USERPROFILE%.cargo\bin) in your
PATH
environment variable. Future applications will automatically have the
correct environment, but you may need to restart your current shell.

测试rust是否成功安装

打开cmd并输入:

rustc --version

你应能看到已发布的最新稳定版的版本号、提交哈希和提交日期, 类似如下格式:

rustc 1.43.0 (4fb7144ed 2020-04-20)

安装程序也自带一份文档的本地拷贝,可以离线阅读。运行 rustup doc 在浏览器中查看本地文档。

cargo加速

.cargo文件夹(就是安装rust里面出现的那个目录, 例如这里是C:\Users\windows\.cargo)中新建config.txt, 在里面写入以下内容, 保存退出, 之后把后缀名去掉, 得到文件config

# Put the content into ${HOME}/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# replace with your favourite mirror
replace-with = 'sjtu'

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

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

[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"

参考文章:
Rust程序设计语言简体中文版-安装
在中国大陆cargo命令速度很慢怎么办

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值