在https://zhuanlan.zhihu.com/p/136848439基础上完善
1、进入rust网址下载对应的x86_64-unknown-linux-gnu 安装文件
https://forge.rust-lang.org/infra/other-installation-methods.html#which
2、chmod +x 777 rustup-init
./rustup-init
source ~/.cargo/env
3、/etc/profile中增加以下环境变量
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
export PATH=~/.cargo/bin:$PATH
export CARGO_HTTP_MULTIPLEXING=false
source /etc/profile
另外也可以使用rproxy镜像加速下载:
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
在 ~/.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"
[http]
check-revoke = false
4. use nightly channel
rustup default nightly
5. Install rust grammar related components
rustup component add rls-preview rust-analysis rust-src
cargo install racer
6. Install rust-analyzer
2020-02-19, update. no need to install rust-analyzer by cargo. install it in vscode plugin, and it will download compiled binary of rust-analyzer.
#no need to install it by following method
git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1
cd rust-analyzer
cargo install-ra
7. The nightly channel need to kept updated, if encounter internal errors from rustc compiler, update the nightly channel may fix the problem.
rustup update
8. install several plugins including for vscode
Firefox quantum theme is the best theme for rust programming. It turn mut variable into red, a good one.
9. Fira Code Retina
with bold font is good for eyes.
11. When the USTC mirror does not work, switch to tsinghua mirror, add following lines into ~/.cargo/config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
#replace-with = 'ustc'
replace-with = 'tuna'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
Useful command tools written in Rust
- An useful shell prompt tool
starship
, install it by
cargo install starship
# in config.fish
starship init fish | source
2. Alternatives to du, ls, cat, grep and more
cargo install rg fd-find du-dust csvtk lsd bat ripgrep
setenv MANPAGER "sh -c 'col -bx | batcat -l man -p'