I want to automatically install packages that I don't have locally installed when I initialize Emacs. I use the following code to install some packages.
(package-initialize)
(mapc #'(lambda (pkg)
(if (not (package-installed-p pkg))
(package-install pkg)))
(list
'json-mode
; ...
However, when loading Emacs, Emacs says the package is not available for installation. However, it exists on the packages buffer.
error: Package `json-mode' is not available for installation
Does anyone know what I am doing wrong?
package-archives
? If you haven't MELPA to it yet, you might need to do that first before calling the code in your question:(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)