Apple Intelligence now features Image Playground, Genmoji, Writing Tools enhancements, seamless support for ChatGPT, and visual intelligence.

Apple Intelligence has also begun language expansion with localized English support for Australia, Canada, Ireland, New Zealand, South Africa, and the U.K. Learn more >

You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to edit hosts file in Sonoma?

After I upgrade to Sonoma, the command "sudo nano /etc/hosts" not working, when I save file, it show me "Cannot open file for writing: Operation not permitted". So how to edit hosts file in Sonoma?

MacBook Pro 14″, macOS 14.0

Posted on Oct 7, 2023 8:09 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 7, 2023 11:45 PM

I find a solution for this, in finder, if the hosts file has a lock on it, use this command to unlock it:


sudo chflags nouchg,noschg /etc/hosts


then it will be editable by root, so you can use "sudo nano /etc/hosts".


BTY, you can find hosts file in finder by this command: "open /etc".

13 replies
Question marked as Top-ranking reply

Oct 7, 2023 11:45 PM in response to linfeee

I find a solution for this, in finder, if the hosts file has a lock on it, use this command to unlock it:


sudo chflags nouchg,noschg /etc/hosts


then it will be editable by root, so you can use "sudo nano /etc/hosts".


BTY, you can find hosts file in finder by this command: "open /etc".

Oct 7, 2023 8:20 PM in response to linfeee

[Edited]

While in terminal, try just to cd /etc, then type cat hosts or ls -l host*

Just to verify the file is actually there and can be viewed and seen.

Your command is correct so its either missing or has bad permissions or even corrupted.

You can also type whereis nano

to make sure it's there. Can you type nano by itself and have it open just to verify it's intact?

Oct 9, 2023 7:30 AM in response to linfeee

linfeee wrote:

You mean homebrew lock my hosts file?

I have no idea what Homebrew does. I just know that when people come to this forum complaining about some basic, 30 year-old command line technique suddenly doesn't work, Homebrew is always involved. I mean every single single.


I think the most likely explanation is that those Homebrew binaries like bash are not working properly after your upgrade to Sonoma. A system or Xcode upgrade is often the trigger for a catastrophic Homebrew failure. l


Unfortunately, I have no idea how to fix it. In most cases, people install Homebrew because they don't know their way around the command line environment. So when that breaks, they are helpless to fix it. All they can do is erase the hard drive and reinstall the operating system. That will work, but you have to remember to be careful during the restore from Time Machine. If you just restore everything, it will restore everything broken again. You have to restore only user accounts and user files. Do not restore any apps, software, system settings, or "other files". You will need to manually reinstall any 3rd party apps that you really need.


I strongly recommend checking with each developer to ensure that said 3rd party apps work on Sonoma. Some will say "yes". Some will say "no". Some won't respond at all. Some will ask you "what is this MacOs X Sonoma?" Only reinstall software made people who respond with a "yes".

How to edit hosts file in Sonoma?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.