5

I am trying to use sudo emacs with no luck so far. When I run with --debug-init I get the following.

Debugger entered--Lisp error: (file-error "Cannot open load file" "no such file or directory "web-mode")

Why would it be different when I am using sudo emacs? Regular emacs runs fine.

Adam Thompson
  • 547
  • 3
  • 14

2 Answers2

11

sudo emacs runs as the root user. One consequence is Emacs won't look for your .emacs in the home directory of your normal user, it will look in root's home directory instead. So none of your config will be loaded, and you don't have access to any packages installed by your normal user.

As mentioned in a comment, you should run Emacs as your normal user, and use tramp to open files as root. If you're trying something more arcane, we'll need more info to help you.

Tyler
  • 21,719
  • 1
  • 52
  • 92
  • 1
    Note that Ubuntu configures `sudo` such that it *does* preserve `$HOME` and Emacs will load the normal .emacs (see https://security.stackexchange.com/questions/18369/issues-with-preserving-home-on-sudo) – npostavs Apr 01 '18 at 14:57
-1

What worked to me after upgrading Ubuntu from 16 to 20:

  1. make sure variable package-user-dir is pointing to place with elpa packages (smth like "~/.emacs.d/elpa" or wherever it is) and make sure is set in user's ~/.emacs file

  2. make symlinks in root home dir

sudo ln -s ~/.emacs /root
sudo ln -s ~/.emacs.d /root/
  1. make sure ~/.emacs.d/ directory and children has "read" rights to non-user (like chmod 755) After that running sudo emacs seems to read all configs right
alex_1948511
  • 129
  • 4