80

I am currently trying to install ENSIME for emacs 24.3.1 following the instructions at https://github.com/ensime/ensime-emacs under the quick start; I've added

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

(when (not package-archive-contents)
  (package-refresh-contents))

to my .emacs file, as instructed. However, when I restart and do M-x package install [RETURN]ensime[RETURN], it returns [No Match] and indeed, I can't find it when I list the packages. However, I can easily find it at http://melpa.milkbox.net/#; what would be causing the discrepancy between what is available through the website and when can be installed from emacs?

Any help is much appreciated; Thank you!

user2187656
  • 935
  • 1
  • 7
  • 8
  • 2
    I've experienced this same problem, and looking at my Emacs config the only difference is that I have `'("melpa" . "http://melpa.milkbox.net/packages/"))` - note the missing `t` argument at the end. Can't remember if this fixed the problem for me or not, but it's easy enough to try. – Nate W. Jul 18 '14 at 21:31
  • Thank you for the suggestion, but I'm afraid it didn't work. – user2187656 Jul 18 '14 at 21:49
  • 16
    Did you try an explicit `M-x packaged refresher contents` before `package-install`? –  Jul 19 '14 at 16:35
  • With `M-: package-archives` you can see the contents of the variable `package-archives`. You might find that it is not what you thought you set it to. In my case as some point I had it customized in custom-set-variables (auto saved at end of .emacs) and this overrides the value I set earlier. – kasterma Aug 16 '15 at 07:25
  • the 't' at the end of the add-to-list call is just so it appends it. – AAAfarmclub May 26 '16 at 04:42
  • @lunaryorn it was `M-x package-refresher-contents` - it really helped! Thanks! – Gwang-Jin Kim Jul 20 '19 at 05:33
  • After fixing @lunaryorn's typos: `M-x package-refresh-contents`, this worked for me. – Mitch1077487 Mar 06 '20 at 19:14

4 Answers4

122

I had to run M-x package-refresh-contents. Once I did that, the files were found.

Here's what my .emacs looks like:

(cond
 ((>= 24 emacs-major-version)
  (require 'package)
  (package-initialize)
  (add-to-list 'package-archives
           '("melpa-stable" . "http://stable.melpa.org/packages/") t)
  (package-refresh-contents)
 )
)
Scott A
  • 7,745
  • 3
  • 33
  • 46
  • 2
    But [getting started](https://melpa.org/#/getting-started) on Melpa says `Enable installation of packages from MELPA by adding an entry to package-archives after (require 'package) and before the call to package-initialize in your init.el or .emacs file: ` – Rohan Bhatia May 13 '18 at 12:26
  • 1
    That reversed order likely is what is causing the need for refreshing; ultimately they're the same thing at startup because the package-initialize has nothing to initialize until after add-to-list. I haven't tried this but I will. – Scott A May 17 '18 at 21:02
  • 1
    calling `package-refresh-contents` fixed the issue for me. – jcubic Jul 13 '18 at 07:22
  • 2
    Isn't `((>= 24 emacs-major-version)` the wrong way 'round? – andy256 Sep 29 '19 at 06:33
47

In my .emacs file I have

;; packages
(when (>= emacs-major-version 24)
  (require 'package)
  (package-initialize)
  (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
  )

Then, M-x package-list-packages

C-s ensime

and there you go:

ensime 20140718.... available ENhanced Scala Interaction Mode for Emacs

Are you sure your emacs can actually get access to internet?

Vic Nmkf
  • 671
  • 6
  • 7
  • it's worth pointing out that this is now outdated, please use http://ensime.org/editors/emacs/install – fommil Aug 12 '16 at 19:15
  • 1
    That's great, thanks! The question is why `package-install` did not find it (I had the same problem with `clang-format`). – Gauthier Sep 01 '16 at 07:38
  • 1
    @Gauthier I found the same behavior. Turns out the package I wanted was already installed that is why `package-install` could not detect it. – Mini Fridge Nov 11 '20 at 15:47
  • Thanks @MiniFridge that was the problem for me. :) – hraban Mar 18 '22 at 07:30
14

After doing the usual editing of .emacs to make melpa avalaible and restarting Emacs, I searched the list of packages for the one I wanted.

M-x package-list-packages
C-s <package_name>

Then I clicked on the name of the package and pressed the install button. I am unsure as to why M-x package-install RET <package_name> failed, but clicking the install button worked for me.

Kevin Tindall
  • 375
  • 5
  • 16
  • 1
    Same issue when trying to install `magit` when running `M-x package-install RET magit` which kept indicating no matches. It showed related packages such as `magit-svn`, `magit-p4`, etc. but not simply `magit`. However, your suggested answer worked in installing it. – Ray May 25 '18 at 18:01
  • 1
    @RayVega I'm glad to know my answer is helping others; thanks for letting me know :) – Kevin Tindall May 29 '18 at 18:55
2

Emacs v28.2

In my case it seems that a previous attempt at getting started with Emacs left me with a "stale" config file ~/.emacs which somehow clashed with ~/.emacs.d/init.el.

So I just deleted ~/.emacs and things started making sense again.

Make sure you have this in your ~/.emacs.d/init.el file:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

Then:

  • M-x package-refresh-content
  • M-x package-install
  • <your-package-name>
customcommander
  • 17,580
  • 5
  • 58
  • 84