Linux集成Rust开发工具链的核心步骤如下:
安装Rust工具链
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env # 激活环境变量
可通过rustup default stable
/nightly
切换版本。# Ubuntu/Debian
sudo apt update && sudo apt install rustc cargo
# Fedora
sudo dnf install rust cargo
配置开发环境
rustup component add rustfmt # 代码格式化
rustup component add clippy # 代码静态分析
验证安装
运行以下命令检查工具链是否正常:
rustc --version # 查看编译器版本
cargo --version # 查看包管理器版本
cargo new hello_world # 创建测试项目
cd hello_world && cargo run # 编译运行示例程序
高级配置(可选)
rustup install <版本号> # 安装特定版本
rustup default <版本号> # 设为默认版本
.cargo/config.toml
文件,指定交叉编译目标(如[target.x86_64-unknown-linux-gnu]
)。通过以上步骤,可快速在Linux上搭建Rust开发环境,满足从基础编程到系统级开发的需求。