0

every time I git clone my configuration of Emacs into a new machine and start Emacs, there will be error message in Emacs:

error: Unable to activate package 'company-auctex'.
Required package 'auctex-11.87' is unavailable

I know I can fix this problem by package-install auctex manually, but is there a way that I can check if activating company-auctex package failed and then install auctex automatically?

  • 1
    Maybe it helps if you run (unless (package-installed-p 'auctex '(11 87)) (package-install 'auctex)) in your init-file. – Tobias May 4 '18 at 13:40
  • I did this, but it keeps saying the same error, and it won't install auctex. (BTW, the version of the auctex is not important). – CodyChan May 7 '18 at 2:44
1

If you're open to a sliiiightly different approach, may I heartily recommend use-package? Rather than "attempt to use, check for error, install if error," use-package will, on first install, check if the package exists at all and install it if needed. It's also effectively a deferred require, which can be very nice for managing package existence without bogging down loading.

This does, of course, mean you have to be sure use-package is installed properly, but the up-side is you only have to manually ensure a single package. I do this as @Tobias suggested, with an addition:

;; Be sure we've fetched the package archive at least once before
;; attempting to install anything.
(unless package-archive-contents
  (package-refresh-contents))

;; Manually check for `use-package`, install if needed
(unless (package-installed-p 'use-package)
  (package-install 'use-package))

Do note: in the case of auctex specifically, the use-package declaration takes a particular form:

(use-package tex
 :ensure auctex)

This is due to an idiosyncracy of auctex itself; see this question and very thorough answer for details.

  • I know everyone is recommending use-package, and I've noticed this package and recommendations years ago, I've tried to use it several times, although it shouldn't be but it is really complicated to me, I don't fully understand how to use it for my init.el(my init.el is a mess) according the docs I've seen. And if I turn all my init.el into using use-package, that would be a lot of work. I'll consider your suggestion and may take a look at the use-package docs again and change my whole init.el once for all. – CodyChan May 7 '18 at 2:56
  • Very reasonable. It can be used partially -- that is, you don't have to convert all-or-nothing. If usage examples are helpful, my emacs configs use use-package extensively: github.com/Gastove/orary/blob/master/init.el – Gastove May 7 '18 at 14:18

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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