6

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.
anol
  • 8,264
  • 3
  • 34
  • 78
  • The manpage mentions the OPAMCURL environment variable - supposedly, you can use it to define a curl replacement used for downloading packages. Have you considered using this? (by setting it to a dummy script that just "fetches" the local sources instead of downloading them) – Frank Schmitt May 05 '15 at 18:19

1 Answers1

5

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.

ivg
  • 34,431
  • 2
  • 35
  • 63
  • 2
    But say you make a change to the pinned package, how do you get opam to recompile it besides doing a tedious unpin then pin again? –  May 05 '15 at 20:08
  • 2
    That's easy, `opam update lwt; opam upgrade lwt` (actually the former command maybe even omitted in some cases, but it is easier just to issue it every time) – ivg May 05 '15 at 20:22
  • I see, I thought that that would only work if the version number actually changed, not if the source change. Thanks! –  May 05 '15 at 20:23