rust安装 mac

375 阅读1分钟
# 编辑文件
$ vim ~/.zshrc
# 在文件中加入以下两句
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
# 接下来运行命令使文件生效
$ source ~/.zshrc
# 然后就可以进行安装

curl https://sh.rustup.rs -sSf | sh

# 或者
curl -sSf https://mirrors.ustc.edu.cn/rust-static/rustup.sh | sh -s
# 安装的时候有三个选项
1. 默认的安装  ,一般我们选择默认安装就好
2. 自定义安装
3. 取消安装

# 进行最后的配置,config可能不存在,创建就完了
$ cd ~/.cargo && vim 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/"

安装完成

#info: default toolchain set to 'stable-x86_64-apple-darwin'

#  stable-x86_64-apple-darwin installed - rustc 1.60.0 (7737e0b5c 2022-04-04)


#Rust is installed now. Great!

#To get started you may need to restart your current shell.
#This would reload your PATH environment variable to include
#Cargo's bin directory ($HOME/.cargo/bin).
// rust相关的二进制命令在  $HOME/.cargo/bin

#To configure your current shell, run:
// 终端的命令行执行
source $HOME/.cargo/env

或者手动
vim ~/.zshrc

export PATH=$PATH:$HOME/.cargo/bin

:wq

source ~/.zshrc

安装镜像的时候只需要把 static.rust-lang.org 换成 mirrors.ustc.edu.cn/rust-static