9

When I try to save changes made in /etc/hosts file on mac i get this error:

"hosts" E212: Can't open file for writing

How can I update it?

Renat Gatin
  • 6,053
  • 5
  • 37
  • 58

3 Answers3

20

I found the solution:

just use "sudo" before vi hosts (it will ask for administrator password). By doing this I, basically, open hosts file with Administrator privileges:

$ sudo vi hosts

and the after modifications :wq works just fine!

Renat Gatin
  • 6,053
  • 5
  • 37
  • 58
4

Launch the Terminal

  $ sudo vi /etc/hosts

and after the modifications

 :wq!
Kiran Sk
  • 873
  • 10
  • 24
2

My problem was that I was running sudo vi etc/hosts instead of sudo vi /etc/hosts ¯_(ツ)_/¯

dani24
  • 2,108
  • 2
  • 26
  • 28