> ## Content Index
> Fetch the complete content index at: https://sgpublic.xyz/llms.txt
> Use this file to discover other available public pages before exploring further.

# Rust 自定义安装目录
- URL: https://sgpublic.xyz/p/2024/08/6aac9cb1810a480001533600/
- Published: 2024-08-24T03:33:55.000Z
- Updated: 2024-08-24T03:33:55.000Z
- Author: Haven Madray
- Tags: 软件开发, #wp-post

创建环境变量，记得应用环境变量：

```
export RUSTUP_HOME=/mnt/core/lib/rustup
export CARGO_HOME=/mnt/core/lib/cargo
export PATH=$PATH:$CARGO_HOME/bin
```

其中 `RUSTUP_HOME` 和 `CARGO_HOME` 可以改成你喜欢的目录。

然后使用[官方安装脚本](https://www.rust-lang.org/zh-CN/tools/install?ref=sgpublic.xyz)安装即可：

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

执行后输出如下：

```
madray@nas:~$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/mnt/core/lib/rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
/mnt/core/lib/cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/mnt/core/lib/cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/home/madray/.profile
/home/madray/.bashrc
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes

Proceed with standard installation (default - just press enter)
Customize installation
Cancel installation
>
```

可以看到 Rustup 将目录设置为了环境变量中的目录。