在 Linux 上配置 Rust 开发环境,一般只需要几个基础步骤和依赖。下面按「最小可用」和「推荐完整」来说明。
Rust 编译需要 C 工具链(用于链接等):
sudo apt update
sudo apt install -y build-essential curl git
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y curl git
sudo pacman -S base-devel curl git
build-essential/Development Tools包含gcc、make等
使用 rustup(Rust 官方版本管理器):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装完成后:
source $HOME/.cargo/env
或重新打开终端。
验证:
rustc --version
cargo --version
rustup component add rustfmt clippy
rustfmt:代码格式化clippy:代码静态检查rustup target add x86_64-pc-windows-gnu
常见示例:
sudo apt install -y libssl-dev pkg-config
常见于:
code
安装扩展:
vim + rust.vimneovim + rust-toolscargo new hello
cd hello
cargo run
看到 Hello, world! 就说明环境 OK 了。
如果你告诉我:
我可以给你更精确的环境配置方案。