This post is asking this question more clearly and concisely.

My code contains the following function to install dependencies:

(defun literef-install-packages()
  "Install any missing packages. The code is taken from

  (setq package-list '(org org-ref pdf-tools smooth-scrolling company))

                    ; list the repositories containing them
  (setq package-archives '(("elpa" . "http://tromey.com/elpa/")
               ("gnu" . "http://elpa.gnu.org/packages/")
               ("marmalade" . "http://marmalade-repo.org/packages/")
               ("melpa" . "http://melpa.milkbox.net/packages/")))
  (unless package-archive-contents

  (dolist (package package-list)
    (unless (eq (package-installed-p package) t)
      (yes-or-no-p (concat
            "The package " (symbol-name package)
            " is not installed. Install it? "))
    (package-install package)
    (when (eq package 'pdf-tools) (pdf-tools-install))))))

This code installs all the required packages besides org, whose earlier (compared to the version in MELPA) version is built-in. In particular, when I try to evaluate (package-install 'org), I get the message saying that the package is already installed. How do I get around this problem?

  • If this question is just asking another question more clearly, why not edit the other question to just make it clearer? Why duplicate the question with a more clear version? – Drew Nov 12 '18 at 16:24
  • @Drew This is what was suggested to me there. See the comments. – AlwaysLearning Nov 12 '18 at 20:11

The trick is to get the structure describing the version available for installation. The following function does just that:

(defun literef-package-desc(pkg)
  (car (cdr (assq pkg package-archive-contents))))

We can now install org:

(package-install (literef-package-desc 'org) 'dont-select)
  • 1
    Can you add an description of how your code is supposed to be used, or anything else that adds to it? – user12563 Nov 12 '18 at 16:06
  • @DoMiNeLa10 Done. – AlwaysLearning Nov 12 '18 at 20:15
  • This will always install the first version returned. If you have multiple archives loaded with the same package (for example "gnu" and "org") this may not be what you want. – Michael Hoffman Jun 8 '20 at 18:01

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