rustup: rustup is not creating $HOME/.cargo/env

I don’t want $HOME/.cargo/env being sourced in my $HOME/.profile or my $HOME/.bashrc. Still, it is convenient to have $HOME/.cargo/env generated since I will source this file anyway under certain circumstances.

However, $HOME/.cargo/env is not created when I perform the installation as shown below

$ curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path -y

Bug or feature?

Thanks a lot,

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

On a side note, when rustup is not creating the $HOME/.cargo/env file, it still shows the following message:

    To configure your current shell, run:
    source $HOME/.cargo/env

which is kind of confusing since the file does not exist.

I think I agree that it’s a bug we’re not writing the env file out on --no-modify-path - I’m working on a test (and from there a fix) right now.

I fully second this! In my case the issue I have is that in some continuous integration system, the .bashrc file is not writable by rustup because of some permission reasons so I need to rely on --no-modify-path but at the same time I want to manually call source $HOME/.cargo/env later on.

@detly :: The issue was already fixed but it was not released yet.

Meanwhile, you can simply reinstall Rust and copy the env file somewhere else so that you can source it yourself. However, when you try to reinstall Rust, you may eventually find a problem: the env file may not be created.

This happens because rustup detects that your $HOME/.profile and $HOME/.bashrc have already been changed. Simply edit your $HOME/.profile and $HOME/.bashrc and remove the line in the end which sources your env file at $HOME/.cargo/env.

Then run rustup once again like shown below and it should create $HOME/.cargo/env.

$ curl https://sh.rustup.rs -sSf | sh -s -- -y

Note: I have a shell script which installs Rust and several cargo plugins which circumvents this trouble. I simply create $HOME/.cargo/env by hand via this bash function:

function __install_rust_rustup_issue_2578 {
cat << EOF > "$HOME"/.cargo/env
#!/bin/sh
# rustup shell setup
# affix colons on either side of \$PATH to simplify matching
case ":\${PATH}:" in
    *:"\$HOME/.cargo/bin":*)
        ;;
    *)
        # Prepending path in case a system-installed rustc must be overwritten
        export PATH="\$HOME/.cargo/bin:\$PATH"
        ;;
esac
EOF
}