As @JulesTamagnan said, you should not use setq
as that will totally replace the default value of package-archives
. You do not need to add Melpa if you are doing it only to install auctex
. But if you want to add Melpa, use add-to-list
as he suggested.
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
The second missing piece is the call to package-refresh-contents
.
Here is what I have:
(require 'package)
;; Load emacs packages and activate them
;; This must come before configurations of installed packages.
;; Don't delete this line.
(package-initialize)
;; `package-initialize' call is required before any of the below
;; can happen
(defvar my-packages '()) ; POPULATE YOUR TO-BE-INSTALLED PACKAGE LIST HERE
;; Auto install the required packages
;; https://github.com/bbatsov/prelude/blob/master/core/prelude-packages.el
;; http://toumorokoshi.github.io/emacs-from-scratch-part-2-package-management.html
(defvar modi/missing-packages '()
"List populated at each startup that contains the list of packages that need
to be installed.")
(dolist (p my-packages)
(when (not (package-installed-p p))
(add-to-list 'modi/missing-packages p)))
(when modi/missing-packages
(message "Emacs is now refreshing its package database...")
(package-refresh-contents)
;; Install the missing packages
(dolist (p modi/missing-packages)
(message "Installing `%s' .." p)
(package-install p))
(setq modi/missing-packages '()))
(package-refresh-contents)
call. If you not installing packages interatively viaM-x list-packages
(which automatically updates your local database for all packages available onpackage-archives
), you need to do this refresh manually. – Kaushal Modi Mar 16 '16 at 21:05use-package
it will install missing packages and their dependencies. It is really great! – Jules Mar 16 '16 at 22:08gnu
archive, like you do. – Stefan Mar 17 '16 at 13:29