rust安装
官方文档
https://www.rust-lang.org/zh-CN/tools/install
windows
下载安装文件
https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
运行安装程序
如果没有安装Visual Studio根据提示安装即可
安装完重启电脑
重启后继续执行rust可执行安装程序,直接回车安装
安装后查看版本
C:\Users\heweiwei>rustc -V
rustc 1.72.0 (5680fa18f 2023-08-23)
linux
linux一般具备gcc环境
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
直接回车安装
安装成功查看版本
[root@desktop-tzgy ~]# rustc -V
rustc 1.72.0 (5680fa18f 2023-08-23)
hello world
[root@desktop-tzgy rust]# cat hello.rs
fn main() {
println!("Hello World!");
}
[root@desktop-tzgy rust]# rustc hello.rs
[root@desktop-tzgy rust]# ls
hello hello.rs
[root@desktop-tzgy rust]# ./hello
Hello World!
[root@desktop-tzgy rust]#
开发环境
windows下推荐安装vscode
如果想使用中文,可安装中文扩展,如下安装成功后会提示重启,之后设置为中文界面

同样的方法安装 rust-analyzer 和 Native Debug 两个扩展
安装后重启vscode
测试:新建一个文件夹 如rust,
在终端中输入命令:cargo new demo
当前文件下下会构建一个名叫 demo 的 Rust 工程目录。

进入工作目录:cd ./demo
编译:cargo build
运行:cargo run

至此,成功的构建了一个 Rust 命令行程序!
linux下使用vim即可
