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.

Crni
  • 123
  • 2
  • You can use `site-start.el` or `default.el` to configure package directories for users. https://www.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`. –  Nov 09 '18 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 09 '18 at 20:33

1 Answers1

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)
Stefan
  • 26,154
  • 3
  • 46
  • 84