Programmatic installation of Julia packages?

In R, I can use install.packages() to install packages programmatically, Similarly, in Python I can use mamba, conda, or pip.

I know how to install Julia packages from the REPL (press “]” to go into Package handler). How do I, however, install Julia packages programmatically (either within Julia, or a .jl, or from a linux-alike shell)?

In an interactive session, the equivalent of ] add StaticArrays via a string macro is as follows.

using Pkg
pkg"add StaticArrays"

More generally, you can do

using Pkg

See 12. API Reference · Pkg.jl for further details.

If you would like a command line interface, see

Additionally, you may be interested in supplying a Project.toml and Manifest.toml. If you Pkg.activate a folder containing these files, and then Pkg.instantitate the environment will be reproduced.

See the documentation on environments: