Rust 语言环境安装:Mac 开发环境 (Homebrew)
说明
Mac 上有两种安装方式,一种是官方的命令行运行:
$ curl https://sh.rustup.rs -sSf | sh
可以参考: Wiki:Rust 语言环境安装:Linux 开发环境(Ubuntu 18)
另一种是使用 Homebrew,这里我们使用此方法来安装,还没有安装 Homebrew 的用户需先自行安装。
以下操作使用 macOS Mojave (10.14.2) 系统,其他比较新的 Mac 系统应该也类似。
brew install rust
命令行:
$ brew install rust
会安装下载已经编译好的二进制文件,总共大几百兆,安装成功后测试下:
$ rustc --version
和
$ cargo --version
Hello World
创建 hello.rs
文件,内容如下:
hello.rs
// This is a comment
// hello.rs
// main function
fn main() {
// Print text to the console
println!("Hello World!");
}
命令行 rustc
将 hello.rs
编译为可自行文件:
$ rustc hello.rs
接下来运行可执行文件:
$ ./hello
Hello World!