简体   繁体   English

覆盖 Rust 安装默认路径 `$HOME/.cargo` 和 `$HOME/.rustup`

[英]Overriding Rust installation default paths `$HOME/.cargo` and `$HOME/.rustup`

In Rust, by default, files are placed in $HOME/.cargo and $HOME/.rustup .在 Rust 中,默认情况下,文件放在$HOME/.cargo$HOME/.rustup中。 Is there any way to override these defaults?有没有办法覆盖这些默认值?

I am trying to debug an obscure issue and I want to try changing the file locations.我正在尝试调试一个晦涩的问题,并且我想尝试更改文件位置。

This is explained in the documentation :在文档中进行了解释:

rustup allows you to customise your installation by setting the environment variables CARGO_HOME and RUSTUP_HOME before running the rustup-init executable. rustup允许您通过在运行rustup-init可执行文件之前设置环境变量CARGO_HOMERUSTUP_HOME来自定义安装。 As mentioned in the Environment Variables section, RUSTUP_HOME sets the root rustup folder, which is used for storing installed toolchains and configuration options.如环境变量部分所述, RUSTUP_HOME设置 root rustup 文件夹,用于存储已安装的工具链和配置选项。 CARGO_HOME contains cache files used by cargo. CARGO_HOME包含货物使用的缓存文件。

Don't forget to update the $PATH or you won't be able to use the binaries.不要忘记更新$PATH否则您将无法使用二进制文件。 Also, if you want that setup to be permanent, export those variables from your shell configuration ( eg .bashrc or .zshrc ):此外,如果您希望该设置是永久的,请从您的 shell 配置中导出这些变量(例如.bashrc.zshrc ):

Note that you will need to ensure these environment variables are always set and that CARGO_HOME/bin is in the $PATH environment variable when using the toolchain.请注意,在使用工具链时,您需要确保始终设置这些环境变量,并且CARGO_HOME/bin位于$PATH环境变量中。

Before installing Rust, set the environment variables CARGO_HOME and RUSTUP_HOME , and make sure they're set when using the toolchain.在安装 Rust 之前,设置环境变量CARGO_HOMERUSTUP_HOME ,并确保在使用工具链时设置它们。

If you're using Bash, then one way to do that is to:如果您使用的是 Bash,那么一种方法是:

  1. Add these two lines to ~/.bashrc :将这两行添加到~/.bashrc

     export CARGO_HOME=/path/to/your/custom/location export RUSTUP_HOME=/path/to/your/custom/location
  2. Restart your shell or source ~/.bashrc by running:通过运行以下命令重新启动您的 shell 或源~/.bashrc

     . ~/.bashrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM