Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installer produced an invalid .bash_profile #2967

Open
bronson opened this issue Mar 18, 2022 · 3 comments · May be fixed by #3092
Open

installer produced an invalid .bash_profile #2967

bronson opened this issue Mar 18, 2022 · 3 comments · May be fixed by #3092

Comments

@bronson
Copy link

bronson commented Mar 18, 2022

Problem

Installing rustup via the bash command messed up my .bash_profile.

The installer truncated the line [ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env" to [ -f "$HOME/.cargo/env" ] && (which is now applying the conditional to some unrelated line) and then appended . "$HOME/.cargo/env" to the end of the file.

Here it is as a patch, my original file in red(-) and the rustup installer's modifications in green(+):

--- a/.bash_profile
+++ b/.bash_profile
@@ -1,7 +1,6 @@
 [[ $- == *i* ]] && [ -f ~/.bashrc ] && source ~/.bashrc
 
-[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
-
+[ -f "$HOME/.cargo/env" ] && 
 # added by Anaconda3 5.0.0 installer
 export PATH="/Users/bronson/anaconda3/bin:$PATH"
 
@@ -9,3 +8,4 @@ export PATH="/Users/bronson/anaconda3/bin:$PATH"
 if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
   . "$HOME/.nix-profile/etc/profile.d/nix.sh"
 fi
+. "$HOME/.cargo/env"

Steps

  1. Add this line to the start of your .bash_profile: [ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
  2. Install rustup via bash: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  3. That line has been modified ... poorly. now the conditional is mistakenly applied to whatever the next line is, and the source line has been moved the end of the file.

Possible Solution(s)

I wish the installer wouldn't try to modify lines it doesn't understand.

Notes

No response

Rustup version

rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.59.0 (9d1b2106e 2022-02-23)`

Installed toolchains

Default host: aarch64-apple-darwin
rustup home:  /Users/bronson/.rustup

stable-aarch64-apple-darwin (default)
rustc 1.59.0 (9d1b2106e 2022-02-23)
@bronson bronson added the bug label Mar 18, 2022
@bronson
Copy link
Author

bronson commented Mar 18, 2022

Interestingly, it did much better with my .zshrc. The exact same line is in there:

[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"

but the installer left it alone (rather than truncating it as it did above with .bash_profile).

This is the behavior I would expect.

@kinnison
Copy link
Contributor

So the reason your .zshrc is left alone is because we edit .zshenv not .zshrc.

The reason that we mess up that line is because we're not checking that there's nothing before the command we "remove" when we are executing cleanup on the rc files.

We'd need to improve this function https://github.com/rust-lang/rustup/blob/master/src/cli/self_update/unix.rs#L55-L75 to fix this.

x3ro pushed a commit to x3ro/rustup that referenced this issue Oct 14, 2022
@x3ro x3ro linked a pull request Oct 14, 2022 that will close this issue
x3ro pushed a commit to x3ro/rustup that referenced this issue Oct 14, 2022
x3ro pushed a commit to x3ro/rustup that referenced this issue Oct 19, 2022
@rkulla
Copy link

rkulla commented Nov 28, 2022

@kinnison I noticed it defaults to .zshenv even on a Mac, which is known to have unexpected behavior that overrides the file. The zshenv file is more for putting personal configuration to run at the very start of shells (interactive and non-interactive).

At least on a Mac, the 'env' in zshenv misleading and ~/.zprofile is a better place to do PATH initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants