# How to add a package but only if it is not already there?

**URL:** <https://discourse.julialang.org/t/how-to-add-a-package-but-only-if-it-is-not-already-there/30674>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 4, 2019, 4:40am UTC](https://discourse.julialang.org/t/how-to-add-a-package-but-only-if-it-is-not-already-there/30674 "2019-11-04T04:40:29Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [November 8, 2019, 1:21am UTC](https://discourse.julialang.org/t/how-to-add-a-package-but-only-if-it-is-not-already-there/30674/21 "2019-11-08T01:21:13Z")

</div>

So I include a snippet over in this other thread I linked above that does exactly what you’re asking for. I agree with many of the poster’s above me that it might not be a good idea, though. Use at your own risk.

> [@Using LanguageServer.jl with eglot in emacs](https://discourse.julialang.org/t/using-languageserver-jl-with-eglot-in-emacs/23125/38):
>
> LanguageServer.jl eglot integration is now packaged up at [https://github.com/non-Jedi/jleglot](https://github.com/non-Jedi/jleglot) and I just created a pending PR to melpa at [https://github.com/melpa/melpa/pull/6531](https://github.com/melpa/melpa/pull/6531). Hope it’s helpful to y’all. slight_smile For anyone wondering how I ended up making sure the project was instantiated, I stole a page from the Revise playbook: try @eval using LanguageServer catch @warn "Unable to import LanguageServer. Instantiating project." Pkg.instantiate() @eval using LanguageS…

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [November 11, 2019, 2:07pm UTC](https://discourse.julialang.org/t/how-to-add-a-package-but-only-if-it-is-not-already-there/30674/22 "2019-11-11T14:07:46Z")

</div>

> [@fredrikekre](#):
>
> the second bullet is wrong

Sorry to come back to this, but here is what just happened on my system:

```julia
(v1.2) pkg> add Coverage
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
 Resolving package versions...
  Updating `~/.julia/environments/v1.2/Project.toml`
  [a2441757] + Coverage v0.9.3
  [d254efa0] ↑ PkgSkeleton v0.2.0 [`~/projets/git/Julia/PkgSkeleton.jl`] ⇒ v0.3.1 [`~/projets/git/Julia/PkgSkeleton.jl`]
  Updating `~/.julia/environments/v1.2/Manifest.toml`
  [a2441757] + Coverage v0.9.3
  [d254efa0] ↑ PkgSkeleton v0.2.0 [`~/projets/git/Julia/PkgSkeleton.jl`] ⇒ v0.3.1 [`~/projets/git/Julia/PkgSkeleton.jl`]

```

I should add that `Coverage` was already installed on my system, although not in the “home” (v1.2) environment. AFAIK these two packages don’t depend on one another, and it does not look like a common dependency of both was upgraded, which in turn would have needed `PkgSkeleton` to be upgraded as well for compatibility reasons. What It looks like (to me !) is `Pkg` is updating the registry and, seeing that a new version of `PkgSkeleton` is available, upgrades it for me (which is nice, although I didn’t ask for it).

I’m not sure what happened in this case, but it is such experiences that made me think that `Pkg` automatically performed upgrades in some cases where it was not strictly needed. This is with v1.2 though; maybe things have changed recently…

---

<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 11, 2019, 10:03pm UTC](https://discourse.julialang.org/t/how-to-add-a-package-but-only-if-it-is-not-already-there/30674/23 "2019-11-11T22:03:35Z")

</div>

Yea, that’s what happened. Anything in the manifest (that is not in the project) is free game for Pkg, but if you implement what we discussed earlier, then this wouldn’t happen.

Also note that in Julia 1.4 this would not happen (in most cases) since Pkg uses a “tiered resolver”, see e.g. [12. API Reference · Pkg.jl](https://julialang.github.io/Pkg.jl/dev/api/#Pkg.add)

[Previous page](https://discourse.julialang.org/t/how-to-add-a-package-but-only-if-it-is-not-already-there/30674.md?page=1)
