you dont own the file shells popup when editing shells file

Viewed 60

I am following this tutorial:

https://betterprogramming.pub/setting-up-your-mac-for-web-development-in-2020-659f5588b883

I am stuck on this part:

To update our default shell to be Homebrew’s Zsh, we need to edit the shell’s whitelist: sudo vim /etc/shells. (If you’re not comfortable with Vim, you can use TextEdit instead by running sudo open /etc/shells.)
Add a new line with /usr/local/bin/zsh, save, and close.
To change the default shell, run: chsh -s /usr/local/bin/zsh.

When I run sudo open /etc/shells and try to edit, it says that I do not own the file shells and that I cannot edit the file. I'm new to MacOS so not sure what I am doing wrong...

1 Answers

sudo open ... runs open as root, but open itself doesn't actually open the file: it just sends a request to TextEdit to open the file, which then runs as your regular user.

But, you don't need an editor to make this change. Just append the new line to the file using tee:

echo "/usr/local/bin/zsh" | sudo tee -a /etc/shells

tee will run as root; the -a option tells tee to append its input to /etc/shells, rather than overwriting the existing contents.

Related