二、Rust安装及国内加速

二、Rust安装及国内加速
  
  这一节我们来看 Rust 的安装,主要涵盖 Mac、CentOS(同样适用于 Aliyun Linux 2)。

1、安装 Rust

MacOS

   以 zsh 为例

# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl https://sh.rustup.rs -sSf | sh
rustup update stable

   并添加环境变量

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

CentOS

   以 zsh 为例

echo '''
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="$HOME/.cargo/bin:$PATH"
''' >> ~/.zshrc
source ~/.zshrc
yum install -y openssl-devel gcc
# apt install -y openssl libssl-dev gcc musl-tools
curl https://sh.rustup.rs -sSf | sh
# curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf > rustup.sh && sh rustup.sh -y  # 非交互式

2、国内仓库加速

   相当于 Java 的 maven 中央仓库,或 Go 的 https://goproxy.cn。
   以 zsh 为例

cat >> ~/.cargo/config << EOF
[source.crates-io]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
EOF
source ~/.zshrc

3、检查安装

rustc --version
cargo --version
rustup --version

   得到类似以下输出,说明安装成功。

rustc 1.46.0 (04488afe3 2020-08-24)
cargo 1.46.0 (149022b1d 2020-07-17)
rustup 1.22.1 (b01adbbc3 2020-07-08)

4、如需要卸载

rustup self uninstall

 
  关于 Windows 平台上的安装,大概有两种方法,一种也是用软件源的方式,第二种是像装 jdk 一样,下载一个 .exe 文件,运行一下即可。

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值