rust-lang / rustup

The Rust toolchain installer
https://rust-lang.github.io/rustup/
Apache License 2.0
6.14k stars 884 forks source link

Respecting the `CARGO_HOME` environment variable after `rustup` was installed #3020

Open fadelights opened 2 years ago

fadelights commented 2 years ago

Problem you are trying to solve

I downloaded rustup via the command provided on the official website:

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

and then followed the on-screen instructions to install it. I then added the CARGO_HOME environment variable to my shell initialization script (.zshrc in my case):

export CARGO_HOME="$HOME/.rust/cargo"

only to find out that the line added to .profile or .zshenv is already using the default location for cargo:

. $HOME/.cargo/env

and also the env script was adding the default bin to my PATH:

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

and so my CARGO_HOME environment variable was effectively doing nothing.

Solution you'd like

I fixed the problem by modifying the line in my shell initialization script to look like below:

. "$CARGO_HOME/env"

And also modified the $CARGO_HOME/env script:

export PATH="${CARGO_HOME}/bin:$PATH"

I think this would make a nice addition to the project: a cleaner rustup install management.

Notes

Since this was a simple enough fix and I've been looking for a way to start contributing to open-source projects, I thought this might be a good first contribution for me. I searched through this repository and the rustup-init.sh file so that I could maybe find the relevant lines of code and fix them--with no success.

If possible, I would like a little bit of guidance on which files to edit so that I can contribute this fix myself.

kinnison commented 2 years ago

Changing CARGO_HOME after installing Rustup is always going to be a bit fraught. In general I'd recommend setting it before you install Rust. If you want to support this kind of thing long term and believe you can come up with something clean then you will need to update the relevant bits in unix.rs most likely.

fadelights commented 2 years ago

Oh never mind then. I thought the issue could be fixed by updating some shell scripts. I'm still very much a Rust newbie and have a hard time understanding what's going on in the unix.rs file.