Rust 语言环境安装:Linux 开发环境(Ubuntu 18) 1 个改进

说明

本文演示在 Ubuntu 18 下安装 Rust,其他 Ubuntu 版本或者其他 Linux 发行操作类似。

开始之前,请确保系统中已经安装了 curl 命令行工具。

开始安装

$ curl https://sh.rustup.rs -sSf | sh

会输出:

Linux 开发环境(Ubuntu 18)

请选择 1,然按 Enter 键:

Linux 开发环境(Ubuntu 18)

配置执行路径

安装工具会自动在 ~/.profile 里加入 ~/.cargo/binPATH 设置,类似以下:

Linux 开发环境(Ubuntu 18)

如果你的文件没有自动加上 PATH 设置,你可以尝试手动加上。

~/.cargo/bin 目录存储着 Rust 的命令工具:

Linux 开发环境(Ubuntu 18)

为了使上面的配置生效,我们需要:

$ source ~/.profile

测试下

$ rustc --version

$ cargo --version

输出:

Linux 开发环境(Ubuntu 18)

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!

输出示例:

Linux 开发环境(Ubuntu 18)

本文为 Wiki 文章,邀您参与纠错、纰漏和优化
讨论数量: 1

编译的helloworld二进制文件居然要几兆。。。

4年前 评论
Coelacanthus 4年前
yue_ze 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!