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:
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 TextEdit.app bundle. So the command I issued is this:
Voila!!
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:
BBEdit also has this capability:
TextWrangler as well:
Voila, again!! When you go to save your file, you will be prompted for your password.
November 16th, 2011 at 1:37 am
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.
Thanks.
December 2nd, 2011 at 2:05 am
What are you using to edit the file? My hunch is that it’s a permissions issue. You do need to have Administrator privileges to modify that file.
December 25th, 2011 at 7:35 pm
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!
January 10th, 2012 at 7:19 am
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.
Password: