13

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)
learningemacs
  • 343
  • 1
  • 3
  • 11

2 Answers2

13

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.

wasamasa
  • 21,803
  • 1
  • 65
  • 97
  • 1
    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 05 '18 at 21:17
  • Comments risk being deleted at any time. Consider moving your comment to an answer. – Drew Mar 05 '18 at 21:55
  • 1
    This helped ; you may have to do [this too](https://emacs.stackexchange.com/a/51772/6701) afterwards. – yPhil Dec 22 '20 at 14:07
8

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)
learningemacs
  • 343
  • 1
  • 3
  • 11
  • 1
    This helped me to realize that I erroneously tried to double quote the package name. – mlt May 17 '20 at 04: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 https://stackoverflow.com/a/24280417/9161344 – ascendants Feb 09 '21 at 01:09