Rust安裝配置
話說前面: 如果你 之前安裝過老版本的 rust 請先解除安裝 我說的是以 msi 檔案安裝的那種, 請進控制台–> 程式中進行解除安裝
首先 下載下傳官網 的 rustup-init.exe 目前版本是 1.18.0
然後下載下傳完 然後點選 rusupt-init.exe
奇迹發生了:

選 2 進行自定義安裝 會一步一步問你 第一個問你是否用 default host tripe 我選的是
第二個會問你 用哪個版本 我輸入 stable
第三個會問你是否 預設修改環境變量 (這個無所謂了可以後期改) 我選是
然後就會安裝…
安裝完成後你會發現在 c 盤–> 使用者—->(你的登陸名下) 會多出兩個檔案夾. rustup 檔案夾和. cargo 檔案夾
如果你不想将這兩個檔案夾放置在 c 盤下那麼就把它們剪切到别的盤符下我是移動到了别的盤符了, 單單移動是不行的
那麼你還得 修改環境變量:
接着添加中科大 rust 源:
在. cargo 檔案夾根目錄下建立一個 config 檔案 沒有任何檔案字尾, 内容為:
[registry]
index = "https://mirrors.ustc.edu.cn/crates.io-index/" [source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc' [source.ustc] registry = "https://mirrors.ustc.edu.cn/crates.io-index/"
下載下傳安裝鏡像時,你隻需要把
https://static.rust-lang.org
換成
https://mirrors.ustc.edu.cn/rust-static
即可!
接着再添加環境變量:
RUSTUP_DIST_SERVER = "http://mirrors.ustc.edu.cn/rust-static"
RUSTUP_UPDATE_ROOT = "http://mirrors.ustc.edu.cn/rust-static/rustup"
将 cargo 加入 path 環境變量:
%CARGO_HOME%\bin
前期工作就可以了 那麼打開 cmd 輸入
檢查 rustup 有無安裝成功
檢查 cargo 安裝
如果 提示沒有預設的 toolchain 那麼 install:
rustup install stable-x86_64-pc-windows-msvc
将 msvc 版設為 default
rustup default stable-x86_64-pc-windows-msvc
如果設定成功 那麼 console 會列印出正确的版本号
安裝插件:
安裝 rustfmt:
首先 cmd 輸入:
rustup show
檢視 目前 toolchain, 初次安裝應該隻有 stable-msvc
那麼進行安裝 stable-gnu
rustup install stable-x86_64-pc-windows-gnu
rustup install nightly-x86_64-pc-windows-msvc
rustup install nightly-x86_64-pc-windows-gnu
安裝 rls-preview rust-analysis rust-src:
參考 https://github.com/rust-lang-nursery/rls
Note (nightly only)
Sometimes the rls-preview component is not included in a nightly build due to certain issues. To see if the component is included in a particular build and what to do if it's not, check #641.
rustup component add rls-preview rust-analysis rust-src --toolchain stable-x86_64-pc-windows-msvc
rustup component add rls-preview rust-analysis rust-src --toolchain stable-x86_64-pc-windows-gnu
rustup component add rust-analysis rust-src --toolchain nightly-x86_64-pc-windows-msvc
rustup component add rust-analysis rust-src --toolchain nightly-x86_64-pc-windows-gnu
安裝 cargo-release:
安裝 cargo-check:
cargo +stable-x86_64-pc-windows-msvc install cargo-check
安裝 rustfmt:
cargo +stable-x86_64-pc-windows-msvc install rustfmt
安裝 rustsym:
cargo +stable-x86_64-pc-windows-msvc install rustsym
安裝 racer:
cargo +stable-x86_64-pc-windows-msvc install racer
設定 rust_src_path 環境變量(此環境變量不應該寫死,在Linux中可以采用靈活的方式确定該變量值)
RUST_SRC_PATH = "%USERPROFILE%\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src"
參考 https://github.com/racer-rust/racer
Fetch the Rust sourcecode
automatically via rustup and run rustup component add rust-src in order to install the source to $(rustc --print sysroot)/lib/rustlib/src/rust/src. Rustup will keep the sources in sync with the toolchain if you run rustup update.
manually from git, or download from https://www.rust-lang.org/install.html (the 'rustc' source download behind the 'source' link is the right one).
Set the RUST_SRC_PATH environment variable to point to the 'src' dir in the Rust source installation
(e.g. % export RUST_SRC_PATH=/usr/local/src/rust/src or % export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src" )
Test on the command line:
racer complete std::io::B (should show some completions)
rust-learning
Chinese
- Translation of the official The Rust Programming Language book
- Translation of the Rust By Example
- RustPrimer
- Chinese Rust Community
- The book in Traditional Chinese
- Translation of The Little Book of Rust Macros