linux rust语言自定义安装

rust语言linux自定义安装

  • 1、下载rustup-init进程
  • 2、修改安装的环境变量,**centos**
  • 3、配置cargo镜像源(解决cargo build无法下载依赖包)

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

可以一键式安装。不介绍

# 可以查看rustup下载脚本,没有什么意义
$ curl https://sh.rustup.rs >rustup.sh

1、下载rustup-init进程

下载链接
linux rust语言自定义安装_第1张图片
下载完成以后,提升该二进制文件的权限

$ chmod 755 rustup-init

2、修改安装的环境变量,centos

本例中,rust的安装目录为/home/environment/rust/

mkdir -p /home/environment/rust/.cargo/

#~/.bashrc
#~/.profile
#~/.zshenv
#~/.bash_profile

# 上述4个文件中添加以下语句


### rust
# rustup home dir
export RUSTUP_HOME="/home/environment/rust/.rustup"
# rust cargo home dir
export CARGO_HOME="/home/environment/rust/.cargo"

if [ -f /home/environment/rust/.cargo/env ]; then
        . /home/environment/rust/.cargo/env
fi

# 用于更新 toolchain
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
# 用于更新 rustup
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
# /home/environment/rust/.cargo/env

#!/bin/sh
# rustup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
    *:"/home/environment/rust/.cargo/bin":*)
        ;;
    *)
        # Prepending path in case a system-installed rustc needs to be overridden
        export PATH="/home/environment/rust/.cargo/bin:$PATH"
        ;;
esac

运行rustup-init二进制文件

./rustup-init

检查~/.profile ~/.bash_profile ~/.bashrc ~/.zshev中,是否存在. $HOME/.cargo/env,如果存在,则删除这条语句。

3、配置cargo镜像源(解决cargo build无法下载依赖包)

# 放到 `/home/environment/rust/.cargo/config.toml` 文件中
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# 替换成你偏好的镜像源
replace-with = 'rsproxy'
#replace-with = 'sjtu'

# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 中国科学技术大学
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# rustcc社区
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"

# rsproxy
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

如果环境由于特殊原因需要配置代理服务器才能进行下载,则添加以下语句

[http]
proxy = "http://xxx.xxx.xxx.xxx:xx"
check-revoke = false
ssl-version = "tlsv1.2"

[https]
proxy = "https://xxx.xxx.xxx.xxx:xx"
check-revoke = false
ssl-version = "tlsv1.3"

[net]
git-fetch-with-cli = false

你可能感兴趣的:(rust,linux,开发语言)