In my .emacs
, I would like to ensure that the s
package, version 1.10.0 or newer, is installed. If I use (use-package s :ensure t)
it will not upgrade the installation on systems with older versions of s
. How do I ensure that the minimum version is present?
1 Answer
This solution does not invoke use-package
, but instead uses the included package.el
functionality. Either way it should get the job done:
;; (source: http://emacs.stackexchange.com/a/22174/93)
(defun package-update (package &optional version)
"Update a package from the package archives.
If VERSION is nil, update the package to the most recent version
available. Otherwise, VERSION should be a version string, or a
list of the type returned by `version-to-list'. The package will
be updated only if the currently installed version is less than
the version specified, even if a newer version is available."
(unless package--initialized
(package-initialize t))
(unless package-archive-contents
(package-refresh-contents))
(let* ((current (cadr (assoc package package-alist)))
(current-version (if current (package-desc-version current) '(-1)))
(pkg-desc (cadr (assoc package package-archive-contents)))
(pkg-version (and pkg-desc (package-desc-version pkg-desc)))
(target-version (or (and (stringp version) (version-to-list version))
version
pkg-version)))
(when (version-list-< current-version target-version)
(if (null pkg-desc)
(error "Package `%s' not found in package archives" package))
(if (version-list-< pkg-version target-version)
(error "A suitable version of `%s' is not available" package))
(package-install pkg-desc)
(if current
(package-delete current)))
nil))
With that function defined, you could add the following to your init
(package-update 's '(1 10 0))
to ensure that your currently-installed version of the s
package is at least version 1.10.0
use-package
source and there doesn't seem to be an obvious way to do it withuse-package
. Is there another way to do it?.emacs
which I share among many environments. They all already have an old version ofs
installed. When I load Emacs next in each of these environments I will get errors due to missing functions in the old version that I would rather avoid. Yes, I can fix them by doing a mass update from thepackage-list-packages
interface one environment at a time. Just like before I haduse-package
I would have installed the packages one environment at a time.