Search code examples
ocamlopam

OPAM: how to locally reinstall a package without re-downloading it?


I want to locally recompile/reinstall a package that has already been downloaded via OPAM, but without downloading it again.

opam reinstall seems to always re-download the package, and I see no option to disable it.

Here are a few reasons one might want to perform this local re-installation:

  • The local sources have been modified, and the person wants to apply the modifications, without having to manually rebuild everything from the original source code;
  • There is currently no Internet connection, or it is slow/capped.

Solution

  • opam will try to keep in sync downloaded package with the upstream one. That means, that if package is in local cache and it doesn't differ from the upstream package, then it wouldn't be downloaded.

    If you want to change source code locally, then you need to pin the package. Other option is to create your own repository and add it to your opam. Your local repository can contain all the packages or only several that you're interested. For handling local repositories there is an opam-admin tool.

    Creating your own repository is not a very easy task, so I would suggest you to use pin command, and pin packages, that you want to have locally, to the specified local path.

    Example (requires opam 1.2 or later)

     opam source lwt.2.4.8
     opam pin add lwt lwt.2.4.8
    

    lwt was chosen arbitrary, just because it is short. The first command will download the sources of the specified version and put them in folder lwt.2.4.8 along with the opam file. The second will force opam tool to use this particular folder as a source for lwt package.