I am trying to edit sources.list using vi editor but getting the following error while saving the file:
/etc/apt/sources.list" E212: Can't open file for writing
Vim has a builtin help system. Running :h E212
inside Vim prints the following:
For some reason the file you are writing to cannot be created or overwritten. The reason could be that you do not have permission to write in the directory or the file name is not valid.
You might want to edit the file as a superuser with sudo vim FILE
. Or if you don't want to leave your existing vim session (and now have proper sudo rights), you can run:
:w !sudo tee % > /dev/null
Which will save the file.