rustup: PATH support doesn't work for fish shell
It’s a popular shell and doesn’t read .profile. cc @nagisa cc https://github.com/rust-lang-nursery/rustup.rs/pull/468
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 144
- Comments: 42 (6 by maintainers)
Commits related to this issue
- Add configuration for Rust https://github.com/rust-lang/rustup/issues/478 — committed to neko314/dotfiles by neko314 2 years ago
An even more fishier way would be to use the fish_user_paths universal variable.
Example:
set -U fish_user_paths $HOME/.cargo/bin $fish_user_pathsNo need to mess with config files. A universal variable, once set, is permanently and persistently set across all fish shell sessions. The contents of that variable are automatically prepended to the $PATH environment variable.
Exporting in a more fisher way
in
~/.config/fish/config.fishmaybe better.I have had this issue a few times. It is easy to resolve.
Create a fish config file in the below directory, if it doesn’t already exist.
~/.config/fish/config.fishThen add the following line to the file.
export PATH="$HOME/.cargo/bin:$PATH"Once you restart your terminal, the rust commands should work again.
rustup create
envwithexport PATH="$HOME/.cargo/bin:$PATH". Why not simply also create a fileenv.fish(like opam) withset -gx PATH "$HOME/.cargo/bin" $PATH;?Hello,
For fish 3.2.0 or upper, released in March 2021, the easiest way to add rust to path permanently is like that:
It will automatically append the specified folder to
fish_user_pathsin$HOME/.config/fish/fish_variables. Documentation can be found here: https://fishshell.com/docs/current/cmds/fish_add_path.htmlI hope it helps
Would a Rust team maintainer be interested in a pull request that checks the shell used and acts accordingly? Concretely, it’s just a small condition in the source file to have the path added automatically (using
fish_add_path) when the user uses Fish as shell.Please let me know.
For people stumbling across it later on. Newer fish versions have a new builtin command for appending to a path:
This can be even called multiple times and will only append once to the path. Note that the builtin errors if the path doesn’t exist.
setting a path manually should be within the skillset of a fish user. and if not - frankly, they should use bash.
Many thanks, this works! And I recommand use
fish_add_path $HOME/.cargo/bin, it’s easier and directly supported by fishshell. 😉Rustup prefers to prepend it’s bin directory to PATH in order to override any system
rustc, so you would want to use-pinstead of-awhen settingfish_user_pathslike so:I think you can just drop the
set -gx ...command in a file in~/.config/fish/conf.d/, see http://fishshell.com/docs/current/index.html#initializationI don’t think people want this feature because it is too difficult to set the path var.
It is the not knowing what to do to fix the issue. If they know they should add to path after install then it should tell the user about it.
Things should be obvious so you can service all types of users and not gatekeep because it makes you feel like hackerman.
Any update here?
I think that
fish_add_pathseems to be the best way for now, as it is shorted and idempotent (it checks is the path is already in thePATHyet)export PATH="$HOME/.cargo/bin:$PATH"works fine 👍Unfortunately nobody who works on
rustupuses fish so we’re not really in a position to know if anything we do would be right. I’ve labelled thisE-mentorbecause I’m prepared to assist someone who knows fish to prepare a PR, but I simply don’t know the right things to do. If you want to help solve this, I’m around either on this issue, or on the Rust discord in#wg-rustupJust want to say that’s not the most fishy of achieving that. You can use the
fish_user_pathvariable or even easier use the utility functionfish_add_user_path. 😌@kinnison I use
fishand am happy to try digging into Rustup if someone can point me in the right direction.Realistically there seems to be only a small handful of non-POSIX shells people actually use, and once support is implemented it probably won’t need much in the way of maintenance.
Hi, any update with this, I think it’s confusing that the script doesn’t even at least mention this issue, nor is it mentioned with the documentation. I believe it’s worthwhile to make change in the installation script to correctly handle for fish.
I would recommend simply running
set -Ua fish_user_paths $HOME/.cargo/binif on fish.¹ It persistently adds the cargo path to path and does not require modifying any file(s).[1] https://github.com/fish-shell/fish-shell/issues/527#issue-10108069
As I commented above, we probably want to solve this is in a way that’s shell-independent. On linux that’d be
.pam_environmentand on macOS we’d uselaunchctl.This will only become more relevant as people start experimenting and depending more with non-POSIX shells such as nushell or powershell. We cannot possibly hope to handle all these different shells in a shell-specific manner.
FWIW OCaml’s opam has a similar problem and handles it just by having a version of the add-stuff-to-PATH hook for each shell. There’s also the “eval (opam config env)” idiom which sets the appropriate environment variables to point to wherever opam thinks they need to point to, including PATH. So a solution like that might work well.
It actually prepends to the path by default, which is even better. That is unless the given directory already exists in the path, in which case it is not moved to the front unless the
-mswitch is given.I still had some issues even after trying
set -Ua fish_user_paths $HOME/.cargo/bin, so instead I added the linesource $HOME/.cargo/envto myconfig.fishfile, which worked!