Append an item to `PATH` variable permanently?

std::env::set_var only works for current running process.

This is an operation system dependet operation, you may search for a crate that does this on or write one for your operating system.

1 Like

Generally you can't. For example, on Linux and macOS there is no central place where env vars are stored. PATH is set temporarily by shell startup script, so to change that, you need to edit code of shell's startup script. And where that code is and how to change it depends on which shell user is using. It's a mess.

Rustup barely manages to do it, so maybe check out how it's done there.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.