Skip to main content
3 of 4
added 220 characters in body
nohillside
  • 104.5k
  • 42
  • 222
  • 275
  1. Open TextEdit as sudo

     sudo -b /Applications/TextEdit.app/Contents/MacOS/TextEdit
    
  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.

grg
  • 205.6k
  • 45
  • 364
  • 496