Windows系统安装rust以及crates换源方式
概要
本篇文章介绍了windows系统rust的安装流程和crates换源的方式。
安装流程
- 在运行rustup-init.exe之前首先需要下载安装,理论上只需要勾选MSVC和windows10 SDK这两个选项。
- 从下载rustup-init.exe
- 运行rustup-init.exe,在一开始的三个选项中选择 1)Proceed with installation (default),之后一直按回车即可完成安装
- 在代码编辑器方面,推荐使用vs code,并且安装rust插件
- 之后让我们来试试写一个hello world并且运行它,新建一个hello_world.rs,写入代码,编译并且运行 fn main(){ println!("hello,world!"); } PS E:OneDrive文档我的路学习之路 ust_work_space> rustc hello_world.rs PS E:OneDrive文档我的路学习之路 ust_work_space> .hello_world.exe hello,world!
- 如果能够运行hello world,说明rust已经成功安装了,这里再补充一点关于crates换源(之后会用到)。下面讲讲怎么换源,首先找到$HOME/.cargo这个文件夹($HOME代表的是C盘的用户目录),然后新建一个config文件(注意这个config文件没有后缀名),然后将以下的内容复制进去,这样就相当于将源换成了清华源。 [source.crates-io] replace-with = tuna [source.tuna] registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"