Rustup and Cargo stopped working after updating /.bash_profile

I do not know the reason of this, but liked to share what happened with me yesterday and today.
Yesterday I did clean and fresh installation of macOS Mojave at my MacBook Air, and installed and worked with Rust.

Today I installed other apps that required me to manually add variables and paths, so I manually adjusted $HOME/.bash_profile

After than, I wanted to update Rust nightly, but rustup gave a wrong command and did not work with me, I tested Cargo it dd not work as well.

I solved it by:

curl -sSf | sh -s -- --no-modify-path 
$ source ~/.cargo/env

This worked fine, but after restarting the laptop, everything back to square one.

The final solution that worked with me is:

// Opened .bash_profile file, I used VS code as editor, this the `code` below
Hasans-Air:~ h_ajsf$ sudo code $HOME/.bash_profile
// Add the below to the .bash_profile file
//Saved the file
//Updated env by:
Hasans-Air:~ h_ajsf$ source $HOME/.bash_profile
//Check for JAVA_HOME
Hasans-Air:~ h_ajsf$ rustup

I’ve no idea why this is happened, I’m new to Mac / Linux and Rust :slight_smile:

source command is for just that running instance of shell, and its effect is gone when you close it (close terminal window, log out, etc.)

Your final solution is correct, and essentially doing what you've prevented by adding --no-modify-path previously.

I understand source ~/.cargo/env is for running instance of shell, I do not understand what rustup stopped working after I adjusted the .bash_profile manually, and added something not related at all to Rust

As you haven’t told us what changes you did exaclty, we can only assume that you (or an installer) deleted the original line that added rustups location to the PATH.

To avoid such things, I keep most of my dotfiles under version control and therefor I’m able to reconstruct everything after scripts messed around with it.

PS: In my opinion, it makes much more sense to put changes in front of PATH rather than at the end.

If you do this:

// Add the below to the .bash_profile file

and your systems administrator installs something globally that has the same name as something you installed via cargo install you wont be able to use your tool anymore.

This is especially annoying if your scripts stop working because of that all of a sudden… (BTDT)