Windows 搭建 Rust 开发环境
source link: https://xugaoxiang.com/2022/11/12/rust-tutorial-1-hello-world/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
- windows 10 64bit
学习 Rust
的第一步当然是安装它,这里使用 rustup
的命令行工具来完成 Rust
的下载与安装,rustup
还被用来管理不同的 Rust
发行版及其附带的工具链。
来到官网 https://www.rust-lang.org/tools/install,选择64位
下载后,双击安装
输入数字 1,进行默认安装
至此,就安装完成了,回车可关闭命令行。安装过程中,程序会将路径 C:\Users\xgx\.cargo\bin
(你的会有差异)加入到系统环境变量 PATH
中
打开终端,输入 rustc --version
来检测 Rust
是否已经被正确地安装了
如果无法识别到 rustc
,就去检查 PATH
环境变量
下面去写个 Hello world
看看,新建一个文件 hello.rs
,用文本编辑器打开并输入下面的代码
fn main() {
println!("Hello, world!");
}
接下来就来编译一下
rustc hello.rs
如果没有报错的话,在同目录就会生成文件 hello.pdb
和 hello.exe
,我们执行 hello.exe
看看结果
终端中输出了 Hello, world!
,恭喜,我们已经完成了第一个 Rust
程序。
几个常用命令
如果要升级 Rust
,可以执行
rustup update
如果不想玩了,可以卸载
rustup self uninstall
Rust
安装过程中为我们准备了详细的文档,可以通过执行下面的命令在浏览器中打开
rustup doc
https://github.com/xugaoxiang/RustTutorial
Rust系列教程
更多 Rust
教程,请移步
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK