1

I tried to customize the ZSH terminal shell (e.g. prompt, auto-completion behavior) by editing the ZSH files, but failed. I have tried both the following, and none worked:

  1. Edit ~/.zshrc:

    When I tried to edit the (blank) file (even under the sudo command), I got the following error message: ".zshrc" E166: Can't open linked file for writing (similar problem happens when trying on .zshenv.
  2. Edit /etc/zshrc:

    This worked, until the computer restarted and resets the file.

What is the correct way to deal with this?

N.B.: I'm running macOS Big Sur 11.6.

3
  • Either chmod the file u+w or use sudo?
    – Dan Bron
    Oct 1 at 23:09
  • 3
    It sounds like you have ~/.zshrc symlinked to something that -- for one reason or another -- cannot be edited. What does ls -l ~/.zshrc show? Oct 1 at 23:27
  • 1
    Why do you think you need to use sudo to edit a file in your own $HOME? Oct 1 at 23:41
1

Undo whatever changes you made to /etc/zshrc, then forget that this file exists. You should be leaving that file alone.

Put your changes in $HOME/.zshrc. This will usually work, zsh should read that file on startup whenever the shell is an interactive one (see man zsh). Note that zsh reads that file regardless of whether or not it is a login shell, so it will be interpreted on every shell invocation.

Forget that sudo exists.

5
  • RE: "Forget that sudo exists." -- That's not very practical as there are many things that one might need to do that require the use of sudo Oct 2 at 3:10
  • @user3439894 The intention there was clearly to say "Forget that sudo exists [when doing this task]"
    – Ezekiel
    Oct 2 at 3:58
  • @marc-wilson thanks for your reply. And that was indeed the first thing that I did. However, like I said: When I tried to edit the (blank) file (even under the sudo command), I got the following error message: ".zshrc" E166: Can't open linked file for writing (similar problem happens when trying on .zshenv. That was why I post here to start with. Do you have any idea why that happened? Thanks! Oct 4 at 0:13
  • Hey! So, it seems that the problem is ~/.zshrc was a symlink, and simply by removing it via sudo rm ~/.zshrc and recreating it does the job! Thanks to this post... Oct 4 at 1:02
  • Please don't tell us you used sudo when you edited the file... Oct 4 at 3:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .