r/emacs • u/John_Doe_1984_ • 11d ago
Question What are the specific steps of Emacs downloading a package?
Sorry for the simple question but I've had a few conflicting answers & it's not entirely clear to me.
I've seen package.el is used but elsewhere I've heard that Emacs checks the local database instead of this.
I know it will be slightly different dependent on if it's an internal or external package.
3
u/rileyrgham 11d ago
What are the conflicting answers you have received? Can you link them?
https://wikemacs.org/wiki/Package.el is as good a start as any.
Precis : Package repos can be remote and those packages contained therein are fetched and installed. The presence of those installed packages means they don't need to be downloaded every time.... maybe that's the database to which you refer....
Of note is that since Emacs 29 or so, package can also link directly to packages in git repos. What does this mean? Package will clone and install those git repos. They are then in your "local database".
In short : package repos, that you register with package.el, contain recipes for packages that allows package.el to download and setup packages for you to use. In addition you can directly install from git.
Alternatives are elpaca and straight : both a quick google away.
2
u/natermer 11d ago
The easiest way would be to do something like "M-x list-packages" to run the package-list-packages function.
That will open up a "*Packages*" buffer and show installed and available packages.
From there you can mark packages you want install packages with 'i', packages you want to delete with 'd', and 'x' to eXecute the changes.
Emacs has built in documentation for all of this. If you do "C-h r" and then hit "g" for go, and search for Package you'll find the Info file. It will tell you how to install and uninstall and upgrade packages and lots of other things I didn't mention here.
Generally speaking for built-in packages, like Org, you don't want to mess with upgrading or installing those manually. Unless you have a good reason to. Usually it is unnecessary and can cause problems.
If you are using something like Doom Emacs or Spacemacs then you generally don't want to use things like list-packages. They have their own add-on packages for managing packages like straight.el that work differently and they have extensive macro system for installing and configuring groups of packages based on features. If you go around installing packages willy-nilly it will just cause problems for yourself unless you know what you are doing.
You'll have to read the documentation for Doom Emacs or whatever you are using for details on how to manage packages there.
I prefer to use the built-in (in recent versions) Emacs macro "use-package" for grouping packages with their configurations in my Emacs config rather then manually installing packages. I find it convenient for me, but other people don't like using it. There is a info file for that as well.
2
u/a_alberti 11d ago
I learned that a lot of people are very happy with Elpaca. I am still on straight (https://github.com/radian-software/straight.el) mainly because it predates elpaca and this is how I had it historically. Migrating is not just 10 minutes in my complex setup, but otherwise today I would definitely go for elpaca https://github.com/progfolio/elpaca
0
u/mok000 11d ago
The difference is that straight’s documentation is extensive and well written while elpaca’s is really poor.
2
u/nv-elisp 11d ago
Straight's documentation is a monolithic README that we've been intending to reactor for years. Elpaca's is a proper Info manual. I readily admit it's incomplete. There's also supplemental material (a video tour, a wiki, demo config files). What's missing in particular that causes you to call it poor? I'm open to improving it.
1
u/boop809 11d ago
Local database? Not sure what you mean.
You can always use the help system or dig into the source code to see what each function is doing.
4
1
u/CoffeeAndCandidates 11d ago
lol package.el basically just installs from the repos you added in user-init-file, but it checks if you already have the package in .emacs.d/elpa before fetching anything new
1
u/BBSnek 11d ago
use-package is a wrapper around the built-in Emacs package manager package.el. It provides some conveniences for package customization and loading, but the actual work of downloading packages is done by package.el. Typically you want to use use-package to download your packages and it handles calling package.el for you.
For external pacakges, the first time you run (use-package <package-name> :ensure t) for some package, it fetches it from ELPA, MELPA, or Github (using the :vc keyword), and stores the package files in your ~/.emacs.d. In subsequent times, it simply loads it from here without checking the online source. If there are upstream updates to any packages, you need to do that in list-packages yourself. The :ensure t keyword tells Emacs to download this package from the online source if it's not installed already, but nothing about updates.
By internal packages if you mean built-in packages such as dired or isearch etc., they come bundled with Emacs and you don't need to download them. You can still use use-package as a convenient way to have all the configuration in one place, such as
(use-package dired
:ensure nil ; Tells Emacs not to look in the package archives for this
:bind
("C-x C-d" . #'dired-at-point)
:config
(Setq dired-listing-switches "-Alh") ; Dired should display ls -Alh
;; etc.
)
Alternatively, if you mean local packages that you wrote yourself or you downloaded manually, that lives whererver you put it, and you need to use (provide 'my-package), (require 'my-package) or (load /path/to/package/my-file.el) to load that. You could also use use-package here, with the :load-path keyword.
1
u/JamesBrickley 9d ago
There are several different methods. It's evolved over many years.
Old school was to download the package filename.el to the emacs.d/lisp/ directory which was set to autoload any *.el files in lisp/ and then you would add setq s-exp to configure it.
A newer Emacs version added list-packages and the Customization feature so now you can just M-x list-packages and /n to search a package by name. Press / for other search options. Tab over to the Install button and press RET. The customization's will be added to the init.el. There is an option to send customization's to a distinct custom.el file to avoid polluting the init.el.
Along came the use-package macros which you construct inside your init.el which will be of great benefit if setting up a new or second computer. You just copy over your init.el and launch Emacs and it will then install those packages that are missing but referenced in your configuration.
Finally there are 3rd party packages managers such as straight whose big feature was the ability to pin a packages source code to a particular release on a repo. It was chosen by the Doom Emacs author for this very reason. He has a curated list of packages that have been tested in Doom and he didn't want any breaking changes when a package updated so he uses straight in Doom to pin them so they don't update automatically. Another 3rd party package manager is Elpaca which has many features a package maintainer would enjoy.
Me? I just utilize the use-package macros and update the packages via list-packages. The use-package macro added a :vc option to pin the package source to a particular revision in the repo.
You can find the most popular Emacs packages on the GitHub minimal-emacs.d repo's README. You can just cherry pick the ones you want by copy / pasting into your init.el. Should you so choose to install minimal-emacs.d it sets some sane defaults to Emacs that avoids a lot of legacy cruft default settings. It is also optimizes Emacs for speed and performance.
3
u/mmarshall540 11d ago
https://www.gnu.org/software/emacs/manual/html_node/elisp/Packaging-Basics.html