$HOME/.cargo/bin permission denied Mac


I need help resolving a permission denied error using this command in terminal (macOS BigSur 11.6):


zsh: permission denied: /Users/myname/.cargo/bin

I have installed rust using these instructions (as I was getting an error using Install Rust - Rust Programming Language).

Can someone advise or help me troubleshoot?
Stack overflow searches and reddit aren't yield successful solutions- I have given terminal full disk access, tried chown commands and still receiving this.

That error looks like zsh is trying to execute .cargo/bin as a binary, which should not work as that's a directory, not an executable.

When is this error happening, and what lines did you add to your profile file?

Edit: Right, that could also happen if you're trying to "cd" into .cargo/bin and don't have permission, but that also usually should never happen.

Thanks for your help,

  • This error is happening when simply executing the $Home/.cargo/bin in the terminal.
  • I don't think I added any lines to my profile file? All I did was use these lines of code to install rust:

curl https://sh.rustup.rs -sSf | sh -s -- --help
& then this:
curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path
finally this:
source ~/.cargo/env

Rereading your note, let me clarify a bit more:

I guess I am trying to complete the final step to "add the bin directory to the path" (watching a tutorial of someone doing this on Windows). I'm not sure if this is needed for Mac?

Why are you executing $HOME/.cargo/bin in a terminal? It is not a command.

I may be misunderstanding, though. Could you paste exactly what you're entering into the terminal?

If what you wantis to add the bin directory to your path, you should be doing something like export PATH="$PATH:$HOME/.cargo/bin". If you add that line to your profile file, it'll run every time you log in, and you'll always have the path set up. Then you can use the rustc, cargo, rustup, etc. commands.

1 Like

Thanks for your help and clarification-- you are understanding correctly, and I understand the error.

rustc was already added to my path (was able to execute rustc from the command line).

I will note export PATH="$PATH:$HOME/.cargo/bin" for the future in case I need to add anything else to path (sorry for being such a command line newb here).

1 Like

Your install may have already added a line with something like that in your shell startup files.
Maybe your PATH is set for cargo/rust. Look at inside your files $HOME/.profile , $HOME/.bashrc
Rustup might have edited those files for you.

1 Like

I think by default, it will execute source ~/.cargo/env

@codelace , @stonerfish if you're curious, open up ~/.cargo/env in a text editor! I expect it will sourcing it will have a very similar effect to executing export PATH="$PATH:$HOME/.cargo/bin". Both should work if placed in your profile file.

Reading up, I think one of your problems might also be related to which profile file you use. Most linux distributions default to using the Bash shell, and thus use ~/.bash_profile. MacOS defaults to a version of ZSH, which uses ~/.zprofile.

If you want new terminals and new graphical sessions to have the tools available, I'd make sure you add either export PATH="$PATH:$HOME/.cargo/bin" or source ~/.cargo/env to either ~/.zprofile or ~/.zshenv.

1 Like

Wanted to say thanks again to both for all the pointers and clarification— it is really helpful in furthering my understanding and solving the problem.

Thought I figured this out but seems I was unsuccessful in permanently adding /.cargo/bin to the PATH environment variable as I ran into issues. Some questions:

  1. Does executing: export PATH="$PATH:$HOME/.cargo/bin" from the .zsh terminal permanently add these to PATH (I.e. everytime I startup a new terminal or graphical session?)— I get the feeling I need to manually add this command to 1 of the 3 profile files (namely, a zsh profile file — it appears to be in .profile)?
  2. If No, do I add export PATH="$PATH:$HOME/.cargo/bin" to the ~/.zprofile file (under the sublime export path)?
  3. If No, do I add export PATH="$PATH:$HOME/.cargo/bin" to ~/.zshrc file?
    3b. I do not have a /.zshenv file. Assuming I did, I'd add source ~/.cargo/env to this file to achieve the same result?
  4. I am confused because I see . "$HOME/.cargo/env" in ~/.profile (see below). Looking at ~/.cargo/env file, it appears to contain the command to add this to PATH, however since I am on .zsh profile, I am unable to access these commands— is this correct?


  • I believe I've consistently been on the ZSH profile ( .zsh in terminal, defaulted by my mac).
  • rustc was added yesterday after installation (as noted above), however cargo was not added. I was able to "run" cargo build and cargo run using the export PATH="$PATH:$HOME/.cargo/bin" command again. End day. Terminal still open.
  • Successfully reran cargo run in same terminal today.
  • Restarted computer today but was unable to use rustc or cargo. Command from .zsh terminal rustc —version yielded zsh: command not found: rustc
  • Came back to this thread to learn more. See below.

Profile states after restarting computer (.zsh terminal):

  • ~/.profile:

    . "$HOME/.cargo/env"

  • ~/.cargo/env


    rustup shell setup

    affix colons on either side of $PATH to simplify matching

    case ":${PATH}:" in
    " # Prepending path in case a system-installed rustc needs to be overridden
    export PATH="$HOME/.cargo/bin:$PATH" "

  • ~./zprofile

    MacPorts Installer addition on 2021-04-15_at_19:05:30: adding an appropriate PATH variable for use with MacPorts.

    export PATH="/opt/local/bin:/opt/local/sbin:$PATH"

    Finished adapting your PATH environment variable for use with MacPorts.

    export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"
    export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"

  • ~./zshrc

    " >>> conda initialize >>>

    !! Contents within this block are managed by 'conda init' !!

    __conda_setup="$('/Users/ilyssaevans/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
    eval "$__conda_setup"
    if [ -f "/Users/ilyssaevans/opt/anaconda3/etc/profile.d/conda.sh" ]; then
    . "/Users/ilyssaevans/opt/anaconda3/etc/profile.d/conda.sh"
    export PATH="/Users/ilyssaevans/opt/anaconda3/bin:$PATH"
    unset __conda_setup

    <<< conda initialize <<<

  • ~/.bash_profile

    " >>> conda initialize >>>

    !! Contents within this block are managed by 'conda init' !!

    __conda_setup="$('/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
    eval "$__conda_setup"
    if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
    . "/opt/anaconda3/etc/profile.d/conda.sh"
    export PATH="/opt/anaconda3/bin:$PATH"
    unset __conda_setup

    <<< conda initialize <<<

  • I do not have a .bashrc file.

That is a good, it is in your .profile as it should be.
now please in your terminal try

echo $PATH

and see if your path is correct.
If it is, then zsh is reading .profile and you might be good to go..

Thanks. Ok did echo $PATH, and returned:

/Users/codelace/opt/anaconda3/bin:/Users/codelace/opt/anaconda3/condabin:/Applications/Sublime Text.app/Contents/SharedSupport/bin:/Applications/Sublime Text.app/Contents/SharedSupport/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin

I don't see .cargo/bin .cargo/env...

Do I add the export PATH="$PATH:$HOME/.cargo/bin to one of these files? Not sure what to do next.

I added export PATH="$HOME/.cargo/bin:$PATH" to .zprofile , restarted, and was able to run rustc and cargo.
I then removed it by .zprofile and added it to .zshrc, restarted, and was able to run rustc and cargo.
This was successful in solving the problem.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.