Function: package-install
package-install is an autoloaded, interactive and byte-compiled
function defined in package.el.gz.
Signature
(package-install PKG &optional DONT-SELECT)
Documentation
Install the package PKG.
PKG can be a package-desc or a symbol naming one of the
available packages in an archive in package-archives. When
called interactively, prompt for the package name.
Mark the installed package as selected by adding it to
package-selected-packages.
When called from Lisp and optional argument DONT-SELECT is
non-nil, install the package but do not add it to
package-selected-packages.
If PKG is a package-desc and it is already installed, don't try
to install it but still mark it as selected.
Probably introduced at or before Emacs version 25.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/package.el.gz
;;;###autoload
(defun package-install (pkg &optional dont-select)
"Install the package PKG.
PKG can be a `package-desc' or a symbol naming one of the
available packages in an archive in `package-archives'. When
called interactively, prompt for the package name.
Mark the installed package as selected by adding it to
`package-selected-packages'.
When called from Lisp and optional argument DONT-SELECT is
non-nil, install the package but do not add it to
`package-selected-packages'.
If PKG is a `package-desc' and it is already installed, don't try
to install it but still mark it as selected."
(interactive
(progn
;; Initialize the package system to get the list of package
;; symbols for completion.
(package--archives-initialize)
(list (intern (completing-read
"Install package: "
(delq nil
(mapcar (lambda (elt)
(unless (package-installed-p (car elt))
(symbol-name (car elt))))
package-archive-contents))
nil t))
nil)))
(package--archives-initialize)
(add-hook 'post-command-hook #'package-menu--post-refresh)
(let ((name (if (package-desc-p pkg)
(package-desc-name pkg)
pkg)))
(unless (or dont-select (package--user-selected-p name))
(package--save-selected-packages
(cons name package-selected-packages)))
(if-let* ((transaction
(if (package-desc-p pkg)
(unless (package-installed-p pkg)
(package-compute-transaction (list pkg)
(package-desc-reqs pkg)))
(package-compute-transaction () (list (list pkg))))))
(progn
(package-download-transaction transaction)
(package--quickstart-maybe-refresh)
(message "Package `%s' installed." name))
(message "`%s' is already installed" name))))