How to remove installed elpa package
Categories:
How to Effectively Remove Installed ELPA Packages in Emacs

Learn the proper methods to uninstall Emacs Lisp Package Archive (ELPA) packages, ensuring a clean removal and preventing configuration issues.
Emacs's package management system, primarily driven by ELPA (Emacs Lisp Package Archive), makes installing new features and extensions incredibly easy. However, knowing how to properly remove packages is just as important to maintain a clean configuration, resolve conflicts, or free up resources. This guide will walk you through the most common and effective ways to uninstall ELPA packages, ensuring a smooth and hassle-free Emacs experience.
Understanding Emacs Package Management
Before diving into removal, it's helpful to understand how Emacs manages packages. When you install a package, Emacs typically downloads its files into a directory like ~/.emacs.d/elpa/
or ~/.emacs.d/straight/repos/
(if using straight.el
). It also updates your package-list-packages
cache and might add entries to your init.el
or config.el
to load the package. Simply deleting the package directory isn't always enough, as lingering configuration or byte-compiled files can sometimes cause issues.
flowchart TD A[User wants to remove package] --> B{Is package installed via `package.el`?} B -- Yes --> C[Use `M-x package-delete`] B -- No --> D{Is package installed via `straight.el`?} D -- Yes --> E[Remove from `straight-use-package` list] D -- No --> F[Manually remove files and config] C --> G[Emacs removes files & updates cache] E --> G F --> G G --> H[Clean up `init.el` or `config.el`] H --> I[Restart Emacs] I --> J[Package successfully removed]
Flowchart of Emacs Package Removal Process
Method 1: Using package-delete
(Recommended for package.el
)
The most straightforward and recommended way to remove packages installed via Emacs's built-in package.el
system is to use the package-delete
command. This method ensures that Emacs correctly unregisters the package and cleans up associated files.
1. Open the Package List
Start Emacs and open the package list by typing M-x package-list-packages
(where M-x
means Alt+x or Esc x, depending on your setup).
2. Mark Package for Deletion
Navigate to the package you wish to delete. You can use C-s
(Ctrl+s) to search. Once found, press d
to mark it for deletion. A D
will appear next to the package name.
3. Execute Deletion
After marking all desired packages, press x
to execute the pending deletions. Emacs will prompt you for confirmation. Type yes
and press Enter to proceed.
4. Clean Up Configuration (Optional but Recommended)
Review your init.el
or config.el
file for any (require 'package-name)
or (use-package package-name ...)
lines related to the deleted package and remove them. This prevents Emacs from trying to load a non-existent package.
5. Restart Emacs
For changes to take full effect and to ensure no lingering byte-compiled files cause issues, it's best to restart Emacs.
use-package
, simply removing the (use-package ...)
declaration from your configuration file and then restarting Emacs will often be sufficient, as use-package
can manage the installation and removal process for you when combined with package.el
.Method 2: Removing straight.el
Packages
If you manage your packages using straight.el
, the process is slightly different as straight.el
handles its own repository cloning and management.
1. Remove from straight-use-package
List
Locate the (straight-use-package 'package-name)
declaration (or similar use-package
block configured for straight.el
) in your init.el
or config.el
file and delete it.
2. Synchronize straight.el
After removing the declaration, restart Emacs. straight.el
will detect that the package is no longer declared and will typically remove its repository from ~/.emacs.d/straight/repos/
during the synchronization process.
3. Manual Cleanup (If necessary)
In rare cases, if the repository isn't automatically removed, you might need to manually delete the package's directory from ~/.emacs.d/straight/repos/
.
~/.emacs.d/elpa/
or ~/.emacs.d/straight/repos/
without first attempting the proper uninstallation methods. This can leave behind byte-compiled files or corrupt your package database, leading to errors.Method 3: Manual Removal (Last Resort)
Manual removal should only be used as a last resort, for instance, if a package was installed outside of package.el
or straight.el
, or if the other methods fail. This involves directly deleting files and cleaning up your configuration.
1. Identify Package Location
Determine where the package files are located. Common locations include ~/.emacs.d/elpa/
, ~/.emacs.d/straight/repos/
, or custom directories you might have added to your load-path
.
2. Delete Package Directory
Close Emacs. Using your file manager or terminal, navigate to the identified location and delete the entire directory corresponding to the package.
3. Remove Configuration Entries
Open your init.el
or config.el
file and meticulously remove all (require 'package-name)
, (load-file "path/to/package.el")
, (add-to-list 'load-path ...)
or any other code related to the package.
4. Delete Byte-Compiled Files
Search for and delete any .elc
(byte-compiled Lisp) files associated with the package that might be scattered in other directories, though this is less common with modern package managers.
5. Restart Emacs
Launch Emacs to ensure all traces are gone and no errors occur.
rm -rf ~/.emacs.d/elpa/package-name-version
# Example for a package named 'magit' version '20230101.1234'
# rm -rf ~/.emacs.d/elpa/magit-20230101.1234
Example of manual directory removal (use with caution)