Fix: rustup “could not amend shell profile: Permission denied” on macOS

Developer tutorial cover: Fix rustup could not amend shell profile, with shell commands in a code editor

You run the official Rust installer on a Mac, press Enter, and it stops with this:

error: could not amend shell profile: '/Users/yourname/.profile': could not write rcfile file: '/Users/yourname/.profile': Permission denied (os error 13)

The installer wants to add Rust to your PATH by editing your shell startup files. It can’t write to one of them. Here’s how to find out why and fix it.

What the error means

Before it installs anything, rustup lists the files it will edit: ~/.profile, ~/.bashrc, ~/.zshenv and ~/.tcshrc. It adds a line to each so that cargo, rustc and rustup work in new terminals. “Permission denied” means your user isn’t allowed to write to one of those files. The error names the first file it failed on. Others may have the same problem.

Step 1: Check who owns the files

ls -l ~/.profile ~/.bashrc ~/.zshenv ~/.tcshrc

A normal file is owned by you:

-rw-r--r--  1 yourname  staff  ...  .profile

If the owner column says root, that’s the cause. The usual way a file ends up owned by root is that an earlier command was run with sudo, and it created or rewrote the file. If a file doesn’t exist, ls says so, which is fine, because rustup creates it.

Step 2 (recommended): Take back ownership

Fix only the files that show root as the owner:

sudo chown "$(whoami)" ~/.profile ~/.bashrc ~/.zshenv ~/.tcshrc

If one of those files doesn’t exist, chown prints “No such file or directory” for it. You can ignore that line.

Check again with ls -l. If the files are yours, the error shouldn’t come back. Run the installer again:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Choose option 1, the standard installation.

If a file is owned by you and still says “Permission denied”, look at its flags and at whether it’s a symlink to something you can’t write to:

ls -ldO ~/.profile

A uchg flag means the file is locked. Don’t remove flags you don’t recognise. Ask whoever set up the Mac first.

Step 3 (alternative): Let rustup skip the PATH edit

If you don’t want rustup to touch your shell files, tell it not to:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path

The --no-modify-path option is documented in the rustup book. Rust installs normally, but nothing adds it to your PATH. Do that yourself. macOS uses zsh by default, so add this line to ~/.zshrc:

. "$HOME/.cargo/env"

Then open a new terminal tab, or run source ~/.zshrc.

Step 4: Check that Rust works

Open a new terminal and run:

rustc --version
cargo --version
rustup --version

Each should print a version. If you get command not found, see Fix: zsh command not found: rustc.

Which fix should you choose?

Situation Fix
A file is owned by root Step 2, change the owner back to you
You’d rather not let rustup edit your shell files Step 3, --no-modify-path
The file is yours and still fails Check flags and symlinks (Step 2) first

Don’t run the installer with sudo

It’s tempting to run sudo sh to get past a permission error. Don’t. rustup installs into your home folder (~/.cargo and ~/.rustup), so it doesn’t need admin rights, and running it as root creates more root-owned files in your home folder. That is how this kind of error starts.

Next: use Rust for Laravel

Once rustc --version works, continue with the Laravel Rust install guide for macOS.

FAQ

Is it safe to delete ~/.profile? I wouldn’t. Check who owns it and fix that instead. It may hold settings you’ve forgotten about.

Does this happen on Apple silicon only? No. The error is about file permissions, not the chip.

Can I undo the install? Yes. rustup self uninstall removes Rust and reverts the shell file changes.

Sources:

Leave a Reply