This question already has an answer here:

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?

marked as duplicate by Drew, DoMiNeLa10 Nov 12 '18 at 18:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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)

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 1
    Can you add an description of how your code is supposed to be used, or anything else that adds to it? – DoMiNeLa10 Nov 12 '18 at 16:06
  • @DoMiNeLa10 Done. – AlwaysLearning Nov 12 '18 at 20:15

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