下面给你一个从零开始在 Linux 上配置 Rust 开发环境的简明流程,适合新手。
rustup(官方推荐)curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装过程中会让你选择:
1) Proceed with installation (default)source $HOME/.cargo/env
或者重新打开终端。
rustc --version
cargo --version
看到版本号就说明成功了 ✅
rustup update
rustup self uninstall
cargo new hello_rust
cd hello_rust
目录结构:
hello_rust
├── Cargo.toml
└── src
└── main.rs
cargo run
输出:
Hello, world!
推荐:
rust-analyzer(必装)Better TOMLrustup component add rustfmt clippy
rustfmt:格式化代码clippy:代码检查使用:
cargo fmt
cargo clippy
有些项目需要系统库:
sudo apt install build-essential pkg-config libssl-dev
sudo dnf groupinstall "Development Tools"
sudo dnf install openssl-devel
rustup doc --book
或在线:https://doc.rust-lang.org/book/
如果你告诉我:
我可以给你更针对性的配置方案。