【Rust 入门学习】1.1 Rust 的安装、升级、卸载

安装

本教程是基于CentOS Stream 9 作为操作系统进行测试的。
对于命令有出入的地方,请自行更改。

下载安装 rustup ,这是一个用于管理 Rust 版本和相关工具的命令行工具,使用 rustup 安装最新稳定版本的 Rust 编译器。

Linux 、macOS、 Windows 的 Linux 子系统(WSL)直接执行以下命令:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl https://sh.rustup.rs -sSf | sh -s -- --help
source "$HOME/.cargo/env"
rustc --version
cargo --version

升级

要升级Rust 和rustup,在shell 运行以下卸载脚本:

rustup update

卸载

要卸载 Rust 和rustup,在shell 运行以下卸载脚本:

rustup self uninstall

实例:hello world

按照惯例,helloword是必做的事情。

在哪儿工作不重要,但是为了方便与规范,建立一个专门的工作目录比较好管理。

mkdir ~/projects
cd ~/projects
mkdir hello_world
cd hello_world

创建一个main.rs

fn main() {
    println!("Hello, world!");
}

保存后运行:

rustc main.rs
./main.rs

直接输出: Hello, world!

如果有报错:

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

这个是没有编译环境,请先安装好环境: sudo dnf install gcc gcc-c++

相关文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注