一.需要用到的工具Homebrew
它是Mac系统中的包管理工具,简称brew。
1.检查是否已经安装brew
text
# 输出版本号说明已经安装
brew --version
2.安装brew(推荐用国内的镜像源)
text
# Shell是zsh的 macOS 10.15 + 默认是 zsh
/bin/zsh -c "$(curl -fsSL [gitee.com/cunkai/Home...](https://link.juejin.cn?target=https%3A%2F%2Fgitee.com%2Fcunkai%2FHomebrewCN%2Fraw%2Fmaster%2FHomebrew.sh "https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh"))"
# Shell是bash的
/bin/bash -c "$(curl -fsSL [gitee.com/cunkai/Home...](https://link.juejin.cn?target=https%3A%2F%2Fgitee.com%2Fcunkai%2FHomebrewCN%2Fraw%2Fmaster%2FHomebrew.sh "https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh"))"
二.用brew安装Rust
text
# 一键安装
brew install rustup
# 初始化 按提示配置就行 一般用default
rustup-init
三.配置环境变量
text
# 不用打开配置文件直接修改
echo 'export PATH="HOME/.cargo/bin:HOME/.cargo/bin:PATH"' >> ~/.bash_profile
# 使配置生效
source ~/.bash_profile
# ~/.zshrc 同上
# 验证安装
rustc --version
cargo --version