curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
上边的很熟悉了, rust的安装命令, 但国内连接起来非常不方便, 有的时候根本没有办法下载到任何东西。
Mac/Linux系统的国内镜像配置
改为以下命令, 输出到test.sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > test.sh
进入test.sh当中, 把RUSTUP_UPDATE_ROOT的值改成国内的镜像地址:
# If RUSTUP_UPDATE_ROOT is unset or empty, default it. RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup"
保存, 退出编辑, 接下来运行下面的命令。
export RUSTUP_DIST_SERVER="https://mirrors.ustc.edu.cn/rust-static" export RUSTUP_UPDATE_ROOT="https://mirrors.ustc.edu.cn/rust-static/rustup"
开始安装
bash ./test.sh
更新rust
rustup self update && rustup update
Windows系统的国内镜像配置
找到powershell, 不需要管理员运行权限,粘贴复制运行以下两条命令,使用中科大的镜像
$ENV:RUSTUP_DIST_SERVER='https://mirrors.ustc.edu.cn/rust-static' $ENV:RUSTUP_UPDATE_ROOT='https://mirrors.ustc.edu.cn/rust-static/rustup'
同样按照上文的开始安装步骤,安装rust
卸载rust的命令
rustup self uninstall
cargo crates的国内镜像配置文件
部分的在机房里测试是搞不通的,所以小编现在没办法在机房用测试机编译,在本地用自己的弱鸡x86机器搞一个docker环境进行编译,编译好了传到服务器上来。
各地区机房的运营商封禁配置略有不同,我测试拉垮的节点,到你那未必,可以自行尝试。
说用苹果arm机可以交叉编译x86程序hello world传到intel服务器上跑生产的,真心请这种知乎类沙壁别瞎叭叭了。
中科大
tee $HOME/.cargo/config.toml <<-'EOF' [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" EOF
阿里云
tee $HOME/.cargo/config.toml <<-'EOF' [source.crates-io] replace-with = "rustcc" [source.rustcc] registry = "https://code.aliyun.com/rustcc/crates.io-index" EOF
下面的就不多余声明改哪个文件了,都在~/.cargo/config.toml这里改,懂的都懂
rsproxy的
[source.crates-io] replace-with = 'rsproxy-sparse' [source.rsproxy] registry = "https://rsproxy.cn/crates.io-index" [source.rsproxy-sparse] registry = "sparse+https://rsproxy.cn/index/" [registries.rsproxy] index = "https://rsproxy.cn/crates.io-index" [net] git-fetch-with-cli = true
清华大学的(2024年7月测试拉垮了)
[source.tuna] registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
中国科学技术大学(2024年7月测试拉垮了)
[source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index"
上海交通大学
[source.sjtu] registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
rustcc社区(2024年7月测试拉跨了)
[source.rustcc] registry = "git://crates.rustcc.cn/crates.io-index"
新版的rust会提示使用config.toml代替config, 那么把$HOME/.cargo/config更名为$HOME/.cargo/config.toml即可
苹果M1~M3 arm架构编译不了rust的tokio周边库
这个坑很早以前就有人发现, 并提出来issue, 官方其实管不起的。谁叫苹果搞这个事情呢。为了解决类似的问题,苹果拿出的解决方案是rosetta2,剩下的由开发者自己想象。如果你是用终端执行rust编译指令, 按照如下去做:
先卸载你mac电脑里的rust。
rustup self uninstall
卸载干净之后, 退出终端, 在访达->应用程序里面找到终端.app右键点击, 详细简介->使用rosetta打开。
这个时候, 是模拟到x86的平台上了, 进终端执行rust安装指令
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
会发现默认推荐的是安装x86_64版本的rust, 这就意味着你再想在M系列芯片上跑arm的rust很有可能还得在终端里折腾一回(除非docker之类的虚拟机硬上)。 小编亲测可以跑通。
2 楼 IP 111.192.***.157 的嘉宾 说道 : 2个月前