Using TextEdit to Modify /etc/hosts File

You can’t just open up your editor of choice to modify the /etc/hosts file on your Mac. You can open the file without any problem, you just can’t save it.

To do this you must have super user privileges. Just being an Administrator isn’t enough. Fortunately, there’s a way to temporarily get super user privileges using the SUDO command. So I fired up Terminal and typed in:

sudo textedit /etc/hosts

Ruh-roh. It wouldn’t let me save the file. Crap. I’m not a Unix guy and VI makes my skin crawl and head hurt, but I was able to use sudo vi /etc/hosts and save the file.

So why couldn’t I get any of the GUI apps to save it?

Turns out, that you need to sudo the actual executable which is inside the bundle. So the command I issued is this:

sudo /Applications/ /etc/hosts


If you happen to own TextMate, then you can save yourself a lot of typing and heartache. TextMate installs a Terminal command called “mate” that allows you to perform the above sudo command. Just type:

mate /etc/hosts

BBEdit also has this capability:

bbedit /etc/hosts

TextWrangler as well:

edit /etc/hosts

Voila, again!! When you go to save your file, you will be prompted for your password.

About the author

Terry Blanchard

I'm the Vice President of Engineering at Readdle, ex-Apple, design evangelist, drummer, and gadget junkie extraordinaire.

8 thoughts on “Using TextEdit to Modify /etc/hosts File”

  1. Hi,

    Thanks for writing this neat post. I’m using Lion 10.7.2 and am having a hard time using terminal and your commands to accomplish anything.

    I’m trying to edit the hosts file so that I can update my iPad to iOS 5.0.1, which I’ve read online that this will help with. My problem is in saving the hosts file, which I’ve read elsewhere is a pain to do. Other people in the comments threads on these sites seemed to have no issues, so I’m assuming it’s an issue with Lion.

    Anyway, I try to save the edited hosts file into the /etc folder, and it tells me I can’t save the replace the file because it’s in use. Any idea on how to get around this issue? I don’t know exactly how it’s in use so that I can get it to not be in use when I go to save the file. I think that’s my issue.


  2. I came here looking for help on my slow Apple wi-fi network, and you solved my problem! Thanks! But I recently ran across this issue about the hosts file and it turns out Apple changed something in Lion, and now to edit the hosts file you have to use this:

    sudo nano /etc/hosts

    It worked for me. And thanks for the wifi help!

  3. I have been trying to use the sudo command as in the instructions but then it gives me this message below, the problem is it doesn’t allow me to type my password when I try…

    WARNING: Improper use of the sudo command could lead to data loss
    or the deletion of important system files. Please double-check your
    typing when using sudo. Type “man sudo” for more information.

    To proceed, enter your password, or type Ctrl-C to abort.


  4. Hi there, I am having a hard time with this sudo comand. I always get the message:
    “2012-05-10 05:09:01.454 TextEdit[875:8107] NSTrackPersistentURLs: LSSharedFileListInsertItemURL() failed at inserting URL file://localhost/etc/hosts (/etc/hosts)”

    I want to change some stuff but can’t seem to open textedit.


  5. Copy the /etc/hosts file to desktop edit with textedit or your editor.
    Copy and paste it back to the /etc/hosts
    You are done!

    This method has always worked for me 😉

Leave a Reply

Your email address will not be published. Required fields are marked *