一键安装rust
$ curl --proto ‘=https’ --tlsv1.2 -sSf https://sh.rustup.rs | sh
要想立即有rustc和cargo等等可执行
$ source ~/.cargo/env
包管理工具cargo
$ cargo new hello_world
$ cd hello_world
$ cargo build
发现卡住 update crates.io
原因:
天朝某神奇的GreatWall
解决办法:
使用中科大的rust源
cd ~/.cargo/
vi config
添加
[source.crates-io]
registry = “https://github.com/rust-lang/crates.io-index”
replace-with = ‘ustc’
[source.ustc]
registry = “git://mirrors.ustc.edu.cn/crates.io-index”
如果所处的环境中不允许使用 git 协议,可以把上面的地址改为
registry = “https://mirrors.ustc.edu.cn/crates.io-index”
输入:wq退出
重新
$ cd ~/hello_world
$ cargo build
编译通过!
$ cargo run
Compiling hello_world v0.1.0 (/Users/zhpan/rust/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 1.96s
Running target/debug/hello_world
Hello, world!