AEM6.5 - Deleting installed packages | Community
Skip to main content
Magicr
Level 6
October 6, 2025
Solved

AEM6.5 - Deleting installed packages

  • October 6, 2025
  • 3 replies
  • 554 views

Hello everyone,

 

I've got a task to create a service for deleting installed packages programmatically. According https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/jackrabbit/vault/packaging/registry/package-summary.html it does existing a way doing it so. Does exists somewhere an working an example how to get access to package manager?

I am completly new on this field.

 

Thanks in advanced.

Best answer by lukasz-m

Hi @magicr,

If you are using AEM 6.5 you can consider to use below tool from ACS Commons, so you may not need to implement anything custom.

However if the implementation is still the key, you can check how above feature has been implemented and how you can operate Package Manager api on code level, here is a link to sample code:

3 replies

giuseppebaglio
Level 10
October 6, 2025

hi @magicr

Please take a moment to review this response here.

Magicr
MagicrAuthor
Level 6
October 6, 2025

Thanks for your answer.  I read this post and I come up with new question: 

According to linked post it is recommended to uninstall a package first. Unfortunatly I forgort to mention I want to delete old packages and want keep the latest three. So my question is: What will happend, if I uninstall previous version of a package, in case if it possible with curl 

arunpatidar
Community Advisor
Community Advisor
October 7, 2025

Hi @magicr 
You can delete the packages directly from JCR via script/manual.

If you will delete/uninstall it from UI, it will try to uninstall content associated with it and install the latest package after that. This I have seen long back in 6.3

but to be sure you can try same in. local and see what happens when you delete or installed older packages.

Arun Patidar
Vishal_Anand
Level 4
October 6, 2025

@magicr  You will need to have Admin access to navigate to CRX package manager. 

Step by step instructions for perform delete operation programmatically:

  1. Decide lookup method

    • By packageId (group:name:version) or by repository path (/etc/packages or /var/packages).
  2. Create a Sling service user and mapping

    • Felix config: my.bundle.symbolic.name:package-delete-service = package-delete-user
    • Grant minimal permissions on package paths.
  3. Build an OSGi service interface (PackageDeletionService) and implementation.

    • Inject ResourceResolverFactory.
  4. Acquire a secure ResourceResolver and JCR Session

    • Use ResourceResolverFactory.getServiceResourceResolver with SUBSERVICE.
    • Always close the resolver (try-with-resources).
  5. Preferred deletion: use Packaging API

    • Use org.apache.jackrabbit.vault.packaging (or com.day.cq.packaging) PackageManager / JcrPackage to locate and remove the package.
    • It handles metadata and registry cleanup.
  6. Fallback: remove JCR nodes directly

    • Validate node exists and check installed state (prevent accidental delete).
    • session.getNode(path).remove(); session.save().
  7. Safety and checks

    • Require a force boolean to delete installed packages.
    • Validate path prefixes (/etc/packages or /var/packages).
    • Log/audit each delete.
  8. Error handling and cleanup

    • Catch RepositoryException, LoginException, IOExceptions.
    • Return clear errors and ensure resourceResolver.close().
  9. Test and deploy

    • Unit tests (mock resolver/packaging).
    • Integration tests in non‑prod: create → install → delete (with/without force).
    • Deploy bundle and configure subservice mapping.

Minimal example (conceptual):

 
Map<String,Object> auth = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, "package-delete-service"); try (ResourceResolver rr = resolverFactory.getServiceResourceResolver(auth)) { Session session = rr.adaptTo(Session.class); // Preferred: use PackageManager to open/delete package if (session.nodeExists(pkgPath)) { session.getNode(pkgPath).remove(); session.save(); } }
lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
October 6, 2025

Hi @magicr,

If you are using AEM 6.5 you can consider to use below tool from ACS Commons, so you may not need to implement anything custom.

However if the implementation is still the key, you can check how above feature has been implemented and how you can operate Package Manager api on code level, here is a link to sample code:

Magicr
MagicrAuthor
Level 6
October 7, 2025

Actually I tagged my question with "Adobe Experiments Manager" and not AACS 🙂 No idea why the tag does not shown.