Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I open the file with TextEdit (I don't want (truly, I am not able) to use vim), it is seen as "locked", even if I modify the permissions of the file via the "Get Info" window.

How can I modify the hosts file with TextEdit?

share|improve this question
I found nano to be a more approachable terminal-based text editor than vim for simple task like this. – Édouard Mar 8 '14 at 12:58
up vote 9 down vote accepted

In one line, from Terminal:

sudo -b "/Applications/" /etc/hosts

Make your changes, save and close.

share|improve this answer
I'm on Mountain Lion and this doesn't work for me unfortunately. Whenever I try to change something I get an error "You don't own the file hosts and don't have permission to write to it". – Saaru Lindestøkke May 31 '15 at 19:37
  1. Open TextEdit as sudo

    sudo -b /Applications/
  2. Open /etc/hosts in this new TextEdit instance using any of the following methods:

    • Append the path to the end of the previous command
    • Use File → Open
    • Drag the file to the sudo'd TextEdit on the Dock

Alternatively, you can edit in Terminal using nano:

SUDO_EDITOR=nano sudo -e /etc/hosts

Using sudo -e ensures that temporary files etc. are handled in the proper way and you don't run into permission issues with them. nano is a simple console-based editor which is quite user-friendly.

share|improve this answer

You could try TextWrangler for this sort of thing; much more capable than TextEdit, and if you use the direct install from BareBones Software instead of the App Store version, it will happily open locked files. When you try, it asks permission, reminding you that you are not a member of the required group, but password entry will allow you to open and edit the file. Plus, it has optional command line additions (also not built in to App Store version) that will allow you to use TextWrangler by entering edit (name of file) to open things directly from Terminal. Open File dialog has a handy "show invisibles" option to help you open and edit hidden or dot-prefixed files too. It's a free app so no risk in trying.

share|improve this answer
sudo nano /private/etc/hosts

to edit the hosts file within Terminal, Control-O to save, then hit enter

share|improve this answer

If you like simple, you can research vim tool which installed on MacOS: sudo vi /etc/hosts

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.