Adam
Adam

Reputation: 3288

Can't install some melpa packages in emacs

I'm just trying out emacs (coming from vim).

$  emacs --version
GNU Emacs 27.2
Copyright (C) 2021 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

$ cat ~/.emacs.d/init.el
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

I've run M-x package-refresh-contents multiple times but still, many packages that I'd like to install aren't listed. For example, go-mode

trying to install go-mode

Any idea where I've messed up? Thanks!

EDIT

I just tried out spacemacs, and the packages I want show up in the list...

Upvotes: 0

Views: 3707

Answers (2)

ErikMD
ErikMD

Reputation: 14723

As explained in the comments, the behavior you got is just a feature of package.el (not a bug :)

Namely, after installing a MELPA package with M-x package-install RET …, this package is not proposed anymore for installation.

To check whether a package has indeed been installed, you can either:

  • Type M-x package-list-packages RET (RET = the Return key),
    and search for your package name: C-s go-mode C-s C-s … (C-s = Ctrl+S).
  • Or just run ls ~/.emacs.d/elpa/ to see if there's a go-mode-YYYYMMDD.* directory.

Side notes

It may be useful to upgrade all installed MELPA packages from time to time, by typing:

  • M-x package-list-packages RET
  • r (refresh the package list)
  • U (mark Upgradable packages)
  • x (execute the installs and deletions)

Also, beyond the builtin Emacs package manager, you may be interested in the use-package tool:

  • to help organizing one's ~/.emacs file in a declarative way,
  • and installing packages automatically (namely, without needing to type M-x package-install by hand) while customizing them;

→ as an example of use, you could take a look at this Gist of mine to help installing Magit.

Upvotes: 2

Y. E.
Y. E.

Reputation: 784

According to your description, it seems MELPA packages aren't loaded at all.
So, firstly, check what C-h v package-archives outputs. Does it output 'melpa' in the returned list?

You may also run M-x package-list-packages and see if you have any melpa archive packages at all in the listed results.

In my configuration I setup package archives explicitly this way:

(require 'package)

(setq package-archives
      '(("gnu" . "https://elpa.gnu.org/packages/")
        ("gnu-devel" . "https://elpa.gnu.org/devel/")
        ("nongnu" . "https://elpa.nongnu.org/nongnu/")
        ("melpa" . "https://melpa.org/packages/")))

Also, since Emacs 27.1 "it is no longer necessary to call 'package-initialize' in your init file".

Therefore, you should be able to safely remove (package-initialize) call or use it conditionally, such as:

(when (< emacs-major-version 27)
  (package-initialize))

Upvotes: 1

Related Questions