How to edit /etc/profile using emacs? I am using Emacs 24.3 on Mac OS X 10.9.4 and I am trying to edit /etc/profile with that. It obviously does not work when starting the GUI version, but for some reason, it also does not work when starting it with sudo from the command line. When I run

sudo emacs /etc/profile


from the terminal, Emacs still complains that the file is in read-only mode and it cannot write it:

Buffer is read-only: #&lt;buffer profile&gt;


What am I doing wrong?
/etc/profile is set to read-only for all users, so just using sudo won't help.

What you can do:


run sudo emacs /etc/profile
type C-x C-q to toggle readonly mode within Emacs
edit whatever you want
type C-x C-s to save it


Alternatively you can run

EDITOR=emacs sudo -e /etc/profile


which automatically creates a temporary copy of the file you want to edit (which makes it a bit safer in case you want to cancel the update).