Rust 语言环境安装:Linux 开发环境(Ubuntu 18)
说明
本文演示在 Ubuntu 18 下安装 Rust,其他 Ubuntu 版本或者其他 Linux 发行操作类似。
开始之前,请确保系统中已经安装了 curl
命令行工具。
开始安装
$ curl https://sh.rustup.rs -sSf | sh
会输出:
请选择 1,然按 Enter
键:
配置执行路径
安装工具会自动在 ~/.profile
里加入 ~/.cargo/bin
的 PATH
设置,类似以下:
如果你的文件没有自动加上 PATH
设置,你可以尝试手动加上。
~/.cargo/bin
目录存储着 Rust 的命令工具:
为了使上面的配置生效,我们需要:
$ source ~/.profile
测试下
$ 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!
输出示例:
编译的helloworld二进制文件居然要几兆。。。