如何在 AlmaLinux 8 上安装 Rust

在本教程中,我们将向您展示如何在 AlmaLinux 8 上安装 Rust。对于那些不知道的人,Rust 通常被称为 rust-lang。 它是由 Mozilla Research 赞助的通用、多范式、现代、跨平台和开源系统编程语言。 Rust 编程语言还有许多其他很酷的特性,包括设备驱动程序、操作系统的低级编码,并且简单化使其易于使用和高效。

本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,并且最重要的是,您在自己的 VPS 上托管您的站点。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo‘ 获取 root 权限的命令。 我将向您展示在 AlmaLinux 8 上逐步安装 Rust 编程语言。您可以按照 CentOS 和 Rocky Linux 的相同说明进行操作。

在 AlmaLinux 8 上安装 Rust

步骤 1. 首先,让我们先确保您的系统是最新的。

sudo dnf update sudo dnf install epel-release sudo dnf install cmake gcc make

步骤 2. 在 AlmaLinux 8 上安装 Rust。

现在我们使用以下命令下载并安装 Rust:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

安装程序下载后,它会运行并首先询问您是要继续、自定义还是取消安装:

info: downloading installer  Welcome to Rust!  This will download and install the official compiler for the Rust programming language, and its package manager, Cargo.  It will add the cargo, rustc, rustup and other commands to Cargo's bin directory, located at:    /home/idroot/.cargo/bin  This can be modified with the CARGO_HOME environment variable.  Rustup metadata and toolchains will be installed into the Rustup home directory, located at:    /home/idroot/.rustup  This can be modified with the RUSTUP_HOME environment variable.  This path will then be added to your PATH environment variable by modifying the profile file located at:    /home/idroot/.profile  You can uninstall at any time with rustup self uninstall and these changes will be reverted.  Current installation options:     default host triple: x86_64-unknown-linux-gnu      default toolchain: stable                profile: default   modify PATH variable: yes  1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >1

安装程序完成后,会向用户提供附加信息:

Rust is installed now. Great! To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH environment variable. Next time you log in this will be done automatically.  To configure your current shell run source $HOME/.cargo/env

最后,运行以下命令来配置您当前的 shell:

source ~/.profile source ~/.cargo/env

通过运行以下命令来验证系统上安装的 Rust 版本:

rustc -V

步骤 3. 创建 Rust 示例项目。

让我们使用“Hello, World!”来测试 Rust。 应用。 首先,使用以下命令创建一个新目录来存放我们的测试:

mkdir ~/rust-projects cd rust-projects nano helloworld.rs

添加以下行:

fn main() { println!("Hello World, this is a test provided by idroot.us"); }

然后,运行以下命令,这将创建一个名为的可执行文件 helloworld 在当前目录中:

rustc helloworld.rs

接下来,使用 execute 命令运行程序:

./helloworld

恭喜! 您已成功安装 Rust。 感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Rust 编程语言。 如需更多帮助或有用信息,我们建议您查看 Rust 官方网站.