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