Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't update hosts file on mac

Tags:

macos

hosts

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?

like image 367
Renat Gatin Avatar asked Aug 06 '15 18:08

Renat Gatin


3 Answers

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!

like image 74
Renat Gatin Avatar answered Nov 15 '22 05:11

Renat Gatin


Launch the Terminal

  $ sudo vi /etc/hosts

and after the modifications

 :wq!
like image 23
Kiran Sk Avatar answered Nov 15 '22 03:11

Kiran Sk


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

like image 2
dani24 Avatar answered Nov 15 '22 04:11

dani24