Reputation: 12930
OPAM is a great Package Manager for OCaml.
Is there a way to install a given list of packages like pip
does in Python (with the command pip -r requirements.txt
)?
We have a small Git repo shared with several people and it would be nice to just install all project dependencies in one go.
And yes, we might have a little shell script or list the packages in a .txt file and pipe it to opam install
... but there might be a better solution.
Thanks
Upvotes: 1
Views: 693
Reputation: 816
Assuming you have your dependencies specified in NAME.opam
(or just opam
) file in your project, you can run
opam install . --deps-only
This will install all dependencies for your package (or packages if you have several opam files in your project).
By default opam ignores uncommitted changes, so if you want to run this command with modified opam files you'll need to add --working-dir
.
Optionally you could lock down versions of dependencies used by running opam lock
, this will create .opam.locked
files. opam-lock
is a separate plugin in 2.0.5 (and likely until 2.1), so opam will prompt to install it.
With lock files present, you should also add --locked
to opam install
to ask it to use lock file and install exactly the same versions.
I would also recommend adding -j X
where X
is the number of cores you have available, that will speed things up.
I typically have the following in my Makefiles:
deps:
opam install . --deps-only --locked --working-dir
The syntax of .opam files is described here
Upvotes: 4