在 CentOS 上配置 Rust 开发环境,有几个常见坑和注意点,下面按「稳定性 / 版本 / 依赖 / 权限」来总结。
tokio、openssl)可能要求新 glibcrustupcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
注意:
source $HOME/.cargo/env
编辑 ~/.cargo/config.toml:
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
或(清华):
replace-with = "tuna"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index"
sudo yum install -y gcc gcc-c++ make cmake \
openssl-devel curl-devel \
perl pkgconfig
opensslreqwest)建议:openssl = { version = "0.10", features = ["vendored"] }
避免系统 OpenSSL 不兼容
rustup target add x86_64-unknown-linux-musl
echo $PATH | grep cargo
rustup update
cargo update
CentOS 上建议:
rustup default 1.75.0
| 问题 | 原因 |
|---|---|
linker cc not found |
没装 gcc |
openssl not found |
没装 openssl-devel |
| 编译极慢 | 没开并行 / 机器弱 |
| 运行报 glibc 错误 | 在低版本 CentOS 跑高版本编的二进制 |
如果你用的是 CentOS 7 还是 8 / 服务器还是容器 / 是否交叉编译,我可以给你更精确的建议。