Rust Installation Issue MacOS (permissions)

I am new to Rust (and programming in general) but I've heard great things about it.

I tried installing Rust on my Mac today (Monterey 12.3.1) and it gives me an error and says that it's a permissions issue.

I copied the Rust install code into Terminal as per the following:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Once I proceed with the install, thats when the error comes up as follows:
error: could not amend shell profile: '/Users/MYUSERNAME/.bash_profile': could not write rcfile file: '/Users/MYUSERNAME/.bash_profile': Permission denied (os error 13)

From Googling around it seems to be a Mac issue, rather than a Rust issue, but would appreciate any assistance to get Rust installed!

You can add source ~/.cargo/env to you .zshrc file (assuming you use zsh which I believe is the default on macOS nowadays)

Hey thanks for the reply.

Yes I use zsh.

Any ideas how to do this on Mac?

If you know how to use vim you can use vim ~/.zshrc. Otherwise maybe open ~/.zshrc will open a suitable text editor?

1 Like

Ok thanks. It did open a text editor but it says I don't own the file.

When I run ls -l -a in Terminal, I noticed that the zsh file is assigned to Root.

Could this be the issue? Or am I way off?

Im so confused because I did try and install Rust with Root access, which installed successfully, but when I restarted the Terminal there was no record of Rust being installed.

Huh, it shouldn't be assigned to root. Your personal .zshrc should be owned by you.

In that case you installed it just for the root user. Rustup doesn't do global installations.

If you really can't figure out how to add source ~/.cargo/env to .zshrc, you can run this command every time you open a new terminal window. In that case it will only apply to this terminal window.

1 Like

Yeah thats the weird part, and I'm assuming the core issue here. Perhaps I need to speak to a Mac wizard to get that resolved.

Thanks so much for your help mate.

You don't need a mac wizard.

Go back to root user and do a

rustup self uninstall

and also remove that ~/.zshrc file when you are root.
Then as your normal user, do the command to install.

Thanks mate.

The first command did not work, even as root. Not sure why.

Would anyone here be able to help me solve this on my machine? Happy to pay for your time.

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.