Rust 安装
以梅佐酒 7/22/2021 Rust
# Windows 子系统 wsl, Ubuntu 安装 Rust
参照官方文档, 安装文档 (opens new window)
# Cargo: Rust 的构建工具和包管理器
cargo build可以构建项目cargo run可以运行项目cargo test可以测试项目cargo doc可以为项目构建文档cargo publish可以将库发布到 crates.io (opens new window)。
# Cargo 更换国内源
- 中科大源
- linux
tee $HOME/.cargo/config <<-'EOF' [source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc' [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index" EOF- Windows
在
C:\Users\user\.cargo下新增config文件加入配置[source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc' [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index" EOF
# 卸载Rust
rustup self uninstall
# 相关问题
# 1. 在Windows wsl 里 run error: linker cc not found
Compiling hello-rust v0.1.0 (/home/rust/hello-rust)
error: linker `cc` not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: could not compile `hello-rust`
To learn more, run the command again with --verbose.
原因缺少 gcc 解决方案
sudo apt-get update
sudo apt install build-essential
# 相关链接
# Rust 2021
- 安装最近的nightly:
rustup update nightly. - 运行
cargo +nightly fix --edition。 - 编辑Cargo.toml并放置cargo-features = ["edition2021"]在顶部(上方[package]),并将编辑字段更改为edition = "2021"。
- 运行
cargo +nightly check以验证它现在可以在新版本中使用。