Skip to content

Julia package manager

Martin Otter edited this page Jul 12, 2019 · 9 revisions

The Julia package manager (Pkg) is used to install and manage sets of packages. It is important to first read the manual of the package manager. Pkg is very powerful, but on the other hand also quite complicated when starting with it. Below additional hints are given that might otherwise not easy to deduce:

  • The package manager defines versions of packages with the Project.toml and Manifest.toml files. It might be necessary to define in the Project.toml file (in a section [compat]) that the package requires Julia 1.1 or later, or that a later version of another package is required. Example:

    [compat]
    julia = "1.1"
    
  • A very basic property is that for every Pkg-environment, exactly one version of a package is used. For example, if an environment contains two packages A and B, and in the Manifest.toml file of package A it is stated that version v1 or later of package C is required and in the Manifest.toml file of package B it is stated that version v2 or later of package C is required, and the latest registered version of package C is version v3, then the package manager installs exactly one version of C (it could be v1, v2, or v3, or another version). With ]status the actually used package versions of the default environment are listed. Note, the Project.toml and Manifest.toml files of a package A are just yet another environment and whatever is stated in A/Manifest.toml is ignored if package A is used in another environment, such as the default environment v1.0.

Typical work flows

Using the latest registered version of a released package A

  1. Make sure that the current directory is not .julia/dev (you can change directory with the command cd("<directory-name>")).
  2. ]add A will install the latest registered version of a released package A.

Using the latest development version of a package A

  1. Use git to clone the desired branch (usually master) into directory .julia/dev. For example, clone package A to .julia/dev/A.
  2. Best to change to the dev directory. For example: cd("C:/Users/name/.julia/dev").
  3. If A is already in the environment, it might be best to first remove it: ]remove A.
  4. ]dev <full-path-name-of-A> will make the development version of A available. For example, if A is in directory C:\Users\name\.julia\dev\A, then use the command ]dev C:\Users\name\.julia\dev\A.
  5. Exactly the source code that is present in .julia\dev\A will be used in the Julia session. Whenever changes to this source code are made (either directly changing some files, or by switching to another branch), then this modified source code is used in the next Julia session. So, Julia has to be terminated with exit(), and then restarted, and then the actual files of .julia\dev\A are used.