Emacs loads my
.emacs.d/init.el startup file just fine when run as a regular user, but refuses to load it when run as
sudo emacs file.type. I have tried changing the owner of
root with no success.
Emacs loads my
When you run as
-s to preserve your environment. It's not maintaining your environment, thus your
HOME directory is lost. Emacs looks in
~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el, so if you lose HOME, you lose the pathing to your startup files.
sudo -s didn't work for me. Here is the work-around I used.
Load emacs as a normal user (so your settings take effect)
- Use the link to migrate your settings to a theme.
- Give your theme a name. (I unclicked the Remove saved theme settings from Custom save file. Don't know if that affected it)
- Click save theme and note where the theme is saved.
- Exit emacs and copy your theme file to your default emacs theme folder (e.g. ./usr/share/emacs/24.4/etc/themes/)
- Now, open emac with sudo.
M-x customize-themesagain and you should see your newly created theme as selectable.
- Click Save Theme Settings and your sudo session will now use your custom theme in the future.
I wish there was a more elegant way of fixing this but it gets the job done.
jmq has the right idea, the issue is because emacs looks in ~/ directories to find your .emacs file and your installed scripts.
His suggestion of
sudo -s, if it works, is the simplest, but there's a good chance it won't work. The problem is really a matter of how your
sudoers is setup. The
sudoers is likely setup to reset your environment, which means it doesn't preserve the HOME directory for your user when it runs the sudo command. The possible options are presented here as the top rated response, and using
-s can't work around most of the
sudoers settings that will screw it up in the first place.
You can easily run emacs with the init file of your choice. For example, the following command
sudo emacs --load ~/.emacsroot -nw filename.ex
- as super user ->
.emacsrootinit file located in the home directory ->
- in console mode ->