Search code examples
ocamlopam

How to upgrade a single package?


I did opam update and then opam upgrade, and now OPAM wants to upgrade 10 packages to more recent versions.

However, for fear of breaking something inadvertently, I'd like to upgrade a single package, without touching the others. This package has no dependencies and it seems that none of the other packages depends on it.

However, doing opam upgrade <package> results in the same thing as opam upgrade, that is, OPAM wants to upgrade all 10 packages, not just the one I want.

I even tried opam install <package>.<new version>, but it also wants to upgrade everything at once.

Is there a way to upgrade just this single package, without touching the rest? In theory nothing should break, but in practice it often happens...


Solution

  • I found out that doing

    opam reinstall <package>.<new version>
    

    allows me to obtain what I want, that is, install only package <package> and its dependencies, without upgrading unrelated packages.

    OPAM emits a warning ([WARNING] <package>.<new version> is not installed.), but it proposes me to install it anyway.

    Afterwards, despite some warnings about the destination directory not being empty (due to the already installed previous version), OPAM was able to install only the desired package, without upgrading everything.

    Notice that the same thing happens if I try to install a new package: because my previous opam update added several packages to the update list, trying to install anything via opam install will trigger the "update everything" algorithm, while opam reinstall won't.

    I don't know if this is undesired behavior, but if so, I hope that it will remain available in future OPAM versions, or that there will be a way to ignore unrelated upgrades.

    Edit: as indicated in this OPAM Github issue, using --criteria=paranoid or --criteria=-changed,-notuptodate can also help with not modifying anything else.