Linux 下的 Rust 工具链全景
一 核心工具链与用途
rustup update、rustup show、rustup default nightly、rustup self uninstall。cargo new、cargo build、cargo run、cargo test、cargo doc、cargo publish。cargo fmt。cargo clippy。二 发行版与系统级安装方式
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh,安装后执行 source "$HOME/.cargo/env" 使环境变量生效;之后可用 rustup update 保持更新。yum module install rust-toolsetdnf install rust-toolsetsudo apt install rustc cargo;优点是系统级统一,但版本通常较旧,适合对版本不敏感的场景。三 常用开发辅助工具
unsafe 代码尤为有用。四 快速搭建与验证步骤
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shsource "$HOME/.cargo/env"rustc --version、cargo --versioncargo new hello && cd hellocargo runcargo fmtcargo clippycargo doc --open五 国内网络优化与常见问题
~/.bashrc 或 ~/.zshrc):
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustupexport RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup~/.cargo/config.toml 配置镜像源:
[source.crates-io]replace-with = 'ustc'[source.ustc]registry = "https://mirrors.ustc.edu.cn/crates.io-index"[net]git-fetch-with-cli = truesudo apt install build-essential gcc make。