一、安装
rust安装部署相对简单,我们可以直接参考官网安装
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
rustc --version
如果显示版本号、提交的 hash 值和提交时间,恭喜你!则 Rust 已成功安装!cargo --version
如果你看到了版本号,一切 OK!
二、idea开发环境搭建
- 创建项目
cargo new hello_world --bin
这个命令传递了--bin参数因为我们的目标是直接创建一个可执行程序,而不是一个库。 - 导入到IDE,这里选的是IntelliJ,先安装rust插件,双击
shift
键,输入plugin
- 选中之后搜索安装就好了,重启IDE,用IDE打开Project,找到main.rs,直接右键运行,如果看到
missing xcrun at:XXXXX
说明你的mac缺少命令行工具,可以选择安装命令行工具或者xcode,下载地址,登陆后下载 - 卸载命令:
rustup self uninstall
,在安装时有提示该命令
三、环境测试
1.idea打开新建项目hello_word
2.打印相关输出
/Users/zhangpeng/.cargo/bin/cargo run --color=always --package hello_world --bin hello_world
Compiling hello_world v0.1.0 (/data/project/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 0.33s
Running `/data/project/hello_world/target/debug/hello_world`
Hello, Arvin, http://www.chinad.top 欢迎你 !
Hello, world!
Process finished with exit code 0