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.
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.
If the command is invoked with a prefix argument, it will allow
upgrading of built-in packages, as if package-install-upgrade-built-in
had been enabled.
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'.
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.
If the command is invoked with a prefix argument, it will allow
upgrading of built-in packages, as if `package-install-upgrade-built-in'
had been enabled."
(interactive
(progn
;; Initialize the package system to get the list of package
;; symbols for completion.
(package--archives-initialize)
(list (intern (completing-read
"Install package: "
package-archive-contents
nil t))
nil)))
(cl-check-type pkg (or symbol package-desc))
(when (or (and package-install-upgrade-built-in
(package--active-built-in-p pkg))
(package-installed-p pkg))
(user-error "Package is already installed"))
(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)))
(when (and (or current-prefix-arg package-install-upgrade-built-in)
(package--active-built-in-p pkg))
(setq pkg (or (cadr (assq name package-archive-contents)) pkg)))
(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))))