Skip to main content
4 of 4
Corrected path for Catalina and later
  1. Open TextEdit as sudo

     sudo -b /System/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