2

I tried to have some Emacs packages from MELPA installed system-wide, following suggestions from this question. I want to have these packages installed under /usr/local/share/emacs/site-lisp/elpa, so as root user, I've created minimal ~/.emacs as follows:

(package-initialize)
(add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(setq package-user-dir "/usr/local/share/emacs/site-lisp/elpa")

Then, I started Emacs as root, and installed packages as usual, everything seemed fine. Then, I've added following at the beggining of ~/.emacs file of an ordinary user:

(package-initialize)
(push "/usr/local/share/emacs/site-lisp/elpa" package-directory-list)

However, this doesn't work, in the sense that neither root user nor ordinary user could use installed packages. For example if I run following command in the scratch buffer of Emacs run as root user (I installed use-package among other packages):

(require 'use-package)

following error is reported:

Debugger entered--Lisp error: (file-missing "Cannot open load file" "No such file or directory" "use-package")
  require(use-package)
  eval((require 'use-package) nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

On the other side, if last line in the root user ~/.emacs file changed to:

(setq package-user-dir "/usr/share/emacs/site-lisp/elpa")

and also the last line in the ordinary user ~/.emacs file deleted, then everything works fine and both users could use installed packages (note that directory /usr/share/emacs/site-lisp/elpa is in package-directory-list by default).

Any hint what could be the problem here? It's not big deal, but I'd just like to keep packages installed this way under /usr/local, since as far as I remember it, according to FHS this would be the right place for packages installed this way.

2
  • You can use site-start.el or default.el to configure package directories for users. gnu.org/software/emacs/manual/html_node/emacs/Init-File.html As for your problem with /usr/local, I'd check the value of load-path.
    – user12563
    Nov 9, 2018 at 19:48
  • Thanks for your reply. Indeed, if I just add (push "/usr/local/share/emacs/site-lisp" load-path) before (package-initialize) in the user ~/.emacs file, everything works fine with packages installed under /usr/local. Also, the line (push "/usr/local/share/emacs/site-lisp/elpa" package-directory-list) seems unneeded any more, probably it gets automatically updated at (package-initialize) from load-path variable.
    – Crni
    Nov 9, 2018 at 20:33

1 Answer 1

0

I believe the problem is here:

(package-initialize)
(push "/usr/local/share/emacs/site-lisp/elpa" package-directory-list)

You add to package-directory-list too late, because package-initialize has already looked for packages to activate and won't notice that you later add more things to the list of directories. You can do the following instead:

(require 'package)
(push "/usr/local/share/emacs/site-lisp/elpa" package-directory-list)
(package-initialize)
1
  • Thanks, indeed that solves the problem too.
    – Crni
    Nov 10, 2018 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.