1

I have this error: /home/sugar/.zshenv:5: command not found: rustc

I installed rust with modify path: y and checked with print $path and observed /home/user/.cargo/bin in first elemnt of $path array. So I have no clue why rustc is not found. Also tried to add .cargo/bin in .zshrc instead of .zshenv but also didn't work.

Error appears as I have this line in .zshenv:

RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/src/

  • Did you log out, and then log in again after your changes? – maulinglawns Sep 4 '18 at 5:33
  • Still the same error, note that I have this line in .zshenv that echo-ing error: RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/src/ – Tuyen Pham Sep 4 '18 at 6:06
  • Do you modify $PATH before the line where you did $RUST_SRC_PATH or after it? – Lie Ryan Sep 4 '18 at 6:25
  • I chose modify path: y so I don't know where and when .cargo/bin added to $path, as I mentioned even I put RUST_SRC_PATH in .zshrc, still error. – Tuyen Pham Sep 4 '18 at 6:40
  • where is rustc? – danblack Sep 4 '18 at 7:22
2

.zshenv is interpreted for every shell invocation including the ones running scripts before ~/.zprofile (for login shells) or ~/.zshrc (interactive shell customisation). So if you set $path in ~/.zshrc or ~/.zprofile, it won't be set yet by the time zsh interprets ~/.zshenv.

Here, it seems you'd want to either customize your login sessions to have ~/.cargo/bin added to your $path and a RUST_SRC_PATH environment variable set.

So if zsh is your login shell, add:

typeset -U path
path+=(~/.cargo/bin)
export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"

To your ~/.zprofile. Then, the next time you login, your environment should be properly configured.

Or put those lines in ~/.zshenv if you want all your zsh invocations to have that environment regardless of whether they were started as part of your login session or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.