12

I am starting to build up a .emacs file to be used as a development environment within Docker containers. I get this error when starting emacs-nox in a Docker container.

Warning (initialization): An error occurred while loading `/root/.emacs':

error: Package `use-package-' is unavailable

Here is the contents of my .emacs

;; require package
(require 'package)

;; add melpa stable
(add-to-list 'package-archives
         '("melpa-stable" . "https://stable.melpa.org/packages/"))

;; add melpa
(add-to-list 'package-archives
         '("melpa" . "http://melpa.milkbox.net/packages/"))

;; Initialise packages
(package-initialize)

;; add use package
(package-install 'use-package)
11

This particular error happens if Emacs failed looking up the latest version of a package, like if there's no package-archives file containing that information. Before installing packages, make sure to run M-x package-refresh-contents so that there is one. Alternatively, use M-x package-list-packages for installing packages, that ensures that the package-archives files are up to date.

3
  • This helped me get it working. I added (package-refresh-contents) to my .emacs file after (package-initialize) and before (package-install 'use-package). – learningemacs Mar 5 '18 at 21:17
  • Comments risk being deleted at any time. Consider moving your comment to an answer. – Drew Mar 5 '18 at 21:55
  • 1
    This helped ; you may have to do this too afterwards. – yPhil Dec 22 '20 at 14:07
6

I am adding this answer as suggested by @Drew.

I appreciate the answer from @wasamasa which allowed me to get this working in my .emacs file.

Here is how I modified my .emacs file.

(package-initialize)

(package-refresh-contents)

(package-install 'use-package)
2
  • 1
    This helped me to realize that I erroneously tried to double quote the package name. – mlt May 17 '20 at 4:49
  • 1
    FYI, this will cause emacs to refresh the list during each launch. Consider adding a conditional, e.g. (unless package-archive-contents (package-refresh-contents)) to avoid reloading your package list each time. See stackoverflow.com/a/24280417/9161344 – ascendants Feb 9 at 1:09

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.