# Pkg.add updates other packages too?

**URL:** <https://discourse.julialang.org/t/pkg-add-updates-other-packages-too/58165>\
**Category:** General Usage\
**Tags:** package-manager\
**Created:** [March 25, 2021, 8:51pm UTC](https://discourse.julialang.org/t/pkg-add-updates-other-packages-too/58165 "2021-03-25T20:51:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 25, 2021, 8:51pm UTC](https://discourse.julialang.org/t/pkg-add-updates-other-packages-too/58165/1 "2021-03-25T20:51:31Z")

</div>

1. I installed Julia 1.6
2. I installed the latest MLJ 0.16
3. I installed [NaiveBayes](https://github.com/dfdx/NaiveBayes.jl).jl but got downgraded to MLJ 0.15.2 without my consent!  
Is this non-consentual downgrading intended?
4. If this is the wrong place please redirect me to the appropriate thread …

```julia

julia> Pkg.add("NaiveBayes")
   Resolving package versions...
   Installed GPUCompiler ─ v0.9.2
   Installed CUDA ──────── v2.6.0
    Updating `~/.julia/environments/v1.6/Project.toml`
  [f6006082] ↓ EvoTrees v0.7.0 ⇒ v0.5.3
  [add582a8] ↓ MLJ v0.16.0 ⇒ v0.15.2
  [d491faf4] ↓ MLJModels v0.14.1 ⇒ v0.13.3
  [9bbee03b] + NaiveBayes v0.5.0

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 27, 2021, 4:01am UTC](https://discourse.julialang.org/t/pkg-add-updates-other-packages-too/58165/2 "2021-03-27T04:01:24Z")

</div>

> [@Albert\_Zevelev](#):
>
> I installed [NaiveBayes](https://github.com/dfdx/NaiveBayes.jl).jl but got downgraded to MLJ 0.15.2 without my consent!  
> Is this non-consentual downgrading intended?

Yes, it is intended, and it is consensual: you executed a function (`Pkg.add`) without reading the documentation. You can pass a keyword parameter to the function to force it to avoid any downgrading.

```julia
julia> using Pkg

help?> Pkg.add
  Pkg.add(pkg::Union{String, Vector{String}}; preserve=PRESERVE_TIERED)
  Pkg.add(pkg::Union{PackageSpec, Vector{PackageSpec}}; preserve=PRESERVE_TIERED)

  Add a package to the current project. This package will be available by using the
  import and using keywords in the Julia REPL, and if the current project is a
  package, also inside that package.

  Resolution Tiers
  ==================

  Pkg resolves the set of packages in your environment using a tiered algorithm. The
  preserve keyword argument allows you to key into a specific tier in the resolve
  algorithm. The following table describes the argument values for preserve (in
  order of strictness):

  Value Description                                                                        
  ––––––––––––––– –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  PRESERVE_ALL Preserve the state of all existing dependencies (including recursive dependencies) 
  PRESERVE_DIRECT Preserve the state of all existing direct dependencies                             
  PRESERVE_SEMVER Preserve semver-compatible versions of direct dependencies                         
  PRESERVE_NONE Do not attempt to preserve any version information                                 
  PRESERVE_TIERED Use the tier which will preserve the most version information (this is the default)

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  Pkg.add("Example") # Add a package from registry
  Pkg.add("Example"; preserve=Pkg.PRESERVE_ALL) # Add the `Example` package and preserve existing dependencies
  Pkg.add(name="Example", version="0.3") # Specify version; latest release in the 0.3 series
  Pkg.add(name="Example", version="0.3.1") # Specify version; exact release
  Pkg.add(url="https://github.com/JuliaLang/Example.jl", rev="master") # From url to remote gitrepo
  Pkg.add(url="/remote/mycompany/juliapackages/OurPackage") # From path to local gitrepo
  Pkg.add(url="https://github.com/Company/MonoRepo", subdir="juliapkgs/Package.jl)") # With subdir

  See also PackageSpec.

```

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 27, 2021, 8:38pm UTC](https://discourse.julialang.org/t/pkg-add-updates-other-packages-too/58165/3 "2021-03-27T20:38:27Z")

</div>

Thanks for referring me to the docs.

The current default option is: `preserve=PRESERVE_TIERED`  
By “consent” I mean avoiding a default option for package resolution and instead asking the user to select an option in REPL.

Or maybe keep the default option in `Pkg.add` as is (with current warnings), but tell the user in `Pkg.status()` which package version is in the current environment and which version is the latest:

```julia
(@v1.6) pkg> status
      Status `C:\Users\azevelev\.julia\environments\v1.6\Project.toml`
              Package Current Latest
  [f6006082] `EvoTrees v0.5.3 v0.7.0`
  [9bbee03b] NaiveBayes v0.5.0 v0.5.0
  [add582a8] `MLJ v0.15.2 v0.16.0`
  [d491faf4] `MLJModels v0.13.3 v0.14.1` 

```

And highlight (in a different color?) which packages in the current environment are not the latest.

I think package resolution is [one](https://discourse.julialang.org/t/how-to-get-latest-version-number-of-a-package/27262) [of](https://discourse.julialang.org/t/julia-v1-4-0-has-been-released/36324/16) [the](https://github.com/JuliaLang/Pkg.jl/issues/1774#issuecomment-616223321) [most](https://github.com/JuliaLang/Pkg.jl/issues/1655) [common](https://stackoverflow.com/questions/57639110/julia-how-to-update-to-the-latest-version-of-a-package-i-e-flux) challenges faced by newcomers to Julia.

It [would help](https://github.com/alan-turing-institute/MLJ.jl/issues/757#issuecomment-807853741) if there was a standard parsimonious tutorial introducing package management to newcomers.
