1. Switch the source to domestic

export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
Copy the code

2. Installation of rust

If you get a network error the first time, just try a few more times

curl https://mirrors.ustc.edu.cn/rust-static/rustup.sh | sh -s
Copy the code

3. Configure the proxy

$ vim ~/.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"
Copy the code

:wq

4. Install tools

Error may occur due to racer installation #! [feature] May not be used on the stable Release channel early switch to nighty version

rustup install nightly
rustup default nightly
Copy the code

Also, if the installation times out, try several more times to continue the installation

 cargo install racer
 racer -V
 cargo install --force rustfmt
 cargo install --force rls
Copy the code

Xcrun: error: The active developer path (“/Applications/Xcode. App/Contents/developer “) does not exist may be due to the Xcode uninstalled, or updated version, so need to reset, Then run the preceding command

sudo xcode-select -r
sudo xcode-select --switch /Library/Developer/CommandLineTools
xcode-select -p
Copy the code

5. Install components

rustup component add rls-preview rust-analysis rust-src
Copy the code

6. Install the VSCode Rust extension

Open VSCode, search for Rust in the extension center, and install the first Rust(RLS). After the installation, set rust-client.channel to stable in VSCode. It is also recommended to set editor.formatonSave to true to format the code with rust-fmt when saving.

Note: Do not have multiple Rust extensions at the same time. You need to uninstall other Rust extensions first to prevent problems.

7. Create a new project and use vscode to test whether the code can be formatted

cargo new test && cd test
Copy the code