你可以先告诉我具体表现(比如报错内容、现象),不过我先把 Ubuntu 上 Rust 常见“配置有问题”的情况和排查办法给你,基本能覆盖 90% 的情况。
rustc --version
cargo --version
不要用 apt 直接装 rust(容易版本旧、缺组件)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
然后:
rustup update
rustup default stable
说明 PATH 没生效
echo 'source "$HOME/.cargo/env"' >> ~/.bashrc
source ~/.bashrc
如果是 zsh:
echo 'source "$HOME/.cargo/env"' >> ~/.zshrc
source ~/.zshrc
报错类似:
cc not found
linker `cc` not found
解决:
sudo apt update
sudo apt install -y build-essential
配置镜像(推荐):
mkdir -p ~/.cargo
~/.cargo/config.toml:
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
rustup self uninstall
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo把下面任意一个贴出来:
cargo build 的完整输出我可以直接告诉你哪一行错了、怎么改。