如何在 Rocky Linux 9 上安装 Rust 编程语言
Rust 是由 Mozilla 开发的免费、开源、多范式、通用编程语言. 这种语言具有许多特性,例如安全性、内存和并发性。开发人员使用 Rust 创建范围广泛的新软件应用程序,例如游戏引擎、操作系统、文件系统、浏览器组件和虚拟现实模拟引擎。
在 Rocky Linux 9 上安装 Rust 编程语言
步骤 1. 第一步是将您的系统更新到最新版本的软件包列表。为此,请运行以下命令:
sudo dnf check-update sudo dnf install dnf-utils sudo dnf install epel-release sudo dnf install cmake gcc make curl clang
步骤 2. 在 Rocky Linux 9 上安装 Rust 编程语言。
默认情况下,Rust 在 Rocky Linux 9 基础存储库中不可用。现在运行以下命令,从官方页面下载最新的稳定版本安装程序 Rust 包到您的系统:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
在您的输出中,您将看到:
home directory, located at:
/root/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory located at:
/root/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/root/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/root/.profile
/root/.bash_profile
/root/.bashrc
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 (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1
键入 1 并按 Enter 开始安装并激活 Rocky Linux 9 上的 Rust 环境:
source ~/.profile source ~/.cargo/env
验证安装的 Rust 版本构建:
rustc -V
步骤 3. 创建示例 Rust 应用程序。
首先,您需要使用以下命令为您的 Rust 项目创建一个目录:
mkdir rust-projects
接下来,切换到您的 Rust 项目目录:
cd rust-projects
现在使用以下命令创建示例应用程序:
nano helloworld.rs
添加以下文件:
fn main() {
println!("Hello World, this is a test provided by idroot.us");}
之后,编译上面创建的应用程序:
rustc helloworld.rs
要在 Rocky Linux 上运行您使用 Rust 创建的应用程序,请使用以下命令运行该程序:
./helloworld
输出:
Hello World, this is a test provided by idroot.us
感谢您使用本教程在 Rocky Linux 9 系统上安装 Rust 编程语言。如需更多帮助或有用信息,我们建议您查看Rust 官方网站。