# How does Pkg determine the version of a package?

**URL:** <https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380>\
**Category:** General Usage\
**Created:** [September 23, 2018, 1:34pm UTC](https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380 "2018-09-23T13:34:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saschatimme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschatimme/32/10313_2.png) [@saschatimme](https://discourse.julialang.org/u/saschatimme)\
**Post date:** [September 23, 2018, 1:34pm UTC](https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380/1 "2018-09-23T13:34:39Z")

</div>

I am confused by the behaviour of Pkg3. It seems that the `version` field in the `Project.toml` is ignored and instead the registries determines the latest available version. I would have expected that the local `Project.toml` of a `dev`ed package always has priority.

Here is an example, maybe I instead something wrong:

```julia
(v1.0) pkg> generate Bar
Generating project Bar:
    Bar/Project.toml
    Bar/src/Bar.jl

(v1.0) pkg> dev ./Bar
 Resolving package versions...
  Updating `~/.julia/environments/v1.0/Project.toml`
  [5a72affa] + Bar v0.1.0 [`~/.julia/environments/v1.0/../../dev/Bar`]
  Updating `~/.julia/environments/v1.0/Manifest.toml`
  [5a72affa] + Bar v0.1.0 [`~/.julia/environments/v1.0/../../dev/Bar`]

```

Now I change the generated `Project.toml` and set `version = "0.2.0"`. Going back to Julia:

```julia
(v1.0) pkg> resolve
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package Bar [5a72affa]:
 Bar [5a72affa] log:
 ├─possible versions are: 0.2.0 or uninstalled
 ├─Bar [5a72affa] is fixed to version 0.2.0
 └─restricted to versions 0.1.0 by an explicit requirement — no versions left

```

I would have expected that Pkg would just recognize that `Bar` is now at version 0.2.0.

I run into concrete problems when I wanted to upgrade a dependency (minor version jump) of a package where the dependency is currently limited to the latest minor version. Since Pkg ignores the `version` field I cannot upgrade it without having a published new version of my dependency.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 23, 2018, 2:17pm UTC](https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380/2 "2018-09-23T14:17:07Z")

</div>

In the `(1.0)` environment, your example package is required as version 0.1.0. After changing the version to 0.2.0, you’re telling Pkg to resolve package versions - and fails, since at your local dev path only 0.2.0 is available.

I think you’re looking for `up`:

```julia
(jDiscourse) pkg> generate BAR
Generating project BAR:
    BAR/Project.toml
    BAR/src/BAR.jl

(jDiscourse) pkg> st
    Status `Project.toml`

(jDiscourse) pkg> dev ./BAR
 Resolving package versions...
  Updating `Project.toml`
  [1e588908] + BAR v0.1.0 [`BAR`]
  Updating `Manifest.toml`
  [1e588908] + BAR v0.1.0 [`BAR`]

shell> nano ./BAR/Project.toml
# changing the version number

(jDiscourse) pkg> st
    Status `Project.toml`
  [1e588908] BAR v0.1.0 [`BAR`]

(jDiscourse) pkg> resolve
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package BAR [1e588908]:
 BAR [1e588908] log:
 ├─possible versions are: 0.2.0 or uninstalled
 ├─BAR [1e588908] is fixed to version 0.2.0
 └─restricted to versions 0.1.0 by an explicit requirement — no versions left

(jDiscourse) pkg> up
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
 Resolving package versions...
  Updating `Project.toml`
  [1e588908] ? BAR v0.1.0 [`BAR`] ⇒ v0.2.0 [`BAR`]
  Updating `Manifest.toml`
  [1e588908] ? BAR v0.1.0 [`BAR`] ⇒ v0.2.0 [`BAR`]

(jDiscourse) pkg> st
    Status `Project.toml`
  [1e588908] BAR v0.2.0 [`BAR`]

```

A local non-registered package can never be restricted by a Registry, since it’s not registered - the required version (i.e., `0.1.0`) is just not available anymore since you changed the version number to `0.2.0`.

EDIT:

It does look like there’s a bug here though, since `resolve` should already do that. Also, `resolve` seems to just be a wrapper around `up` [with some arguments](https://github.com/JuliaLang/julia/blob/e7d15d4a013a43442b75ba4e477382804fa4ac49/stdlib/Pkg/src/API.jl#L189-L190).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 20, 2018, 5:22pm UTC](https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380/3 "2018-11-20T17:22:26Z")

</div>

Related question: if I forget to bump the version in `Project.toml` when I release packages with the current attobot setup, that is at the moment innocuous, except for `pkg> status` showing wrong versions _for `dev`’ed packages_. Is this correct?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 20, 2018, 10:59pm UTC](https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380/4 "2018-11-20T22:59:19Z")

</div>

When the project file is ur d for tagging the version in there will determine what version you tag.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 23, 2018, 2:02pm UTC](https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380/5 "2018-11-23T14:02:32Z")

</div>

I was asking more about the current state of affairs. Specifically, is it OK if I _don’t_ specify a `version` in `Project.toml` for now?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 23, 2018, 2:03pm UTC](https://discourse.julialang.org/t/how-does-pkg-determine-the-version-of-a-package/15380/6 "2018-11-23T14:03:17Z")

</div>

Currently the version in `Project.toml` file is only used when you are in a checked out state.
