# New Pkg: how to check if a package is installed?

**URL:** <https://discourse.julialang.org/t/new-pkg-how-to-check-if-a-package-is-installed/13141>\
**Category:** General Usage\
**Tags:** pkg\
**Created:** [August 10, 2018, 3:13am UTC](https://discourse.julialang.org/t/new-pkg-how-to-check-if-a-package-is-installed/13141 "2018-08-10T03:13:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![crbinz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crbinz/32/1919_2.png) [@crbinz](https://discourse.julialang.org/u/crbinz)\
**Post date:** [August 10, 2018, 3:13am UTC](https://discourse.julialang.org/t/new-pkg-how-to-check-if-a-package-is-installed/13141/1 "2018-08-10T03:13:01Z")

</div>

For instance, if one wants to use [OhMyREPL](https://github.com/KristofferC/OhMyREPL.jl) automatically upon startup, the [docs](https://kristofferc.github.io/OhMyREPL.jl/latest/installation.html#Installation-1) say to put

```julia
if isdir(Pkg.dir("OhMyREPL"))
    @eval using OhMyREPL
else
    warn("OhMyREPL not installed")
end

```

into `~/.juliarc.jl`. Putting this into [`~/.julia/config/startup.jl`](https://discourse.julialang.org/t/equivalent-of-juliarc-jl-in-v0-7/11534) and adding `import Pkg` up front results in

```julia
┌ Warning: `Pkg.dir(pkgname, paths...)` is deprecated; instead, do `import OhMyREPL; joinpath(dirname(pathof(OhMyREPL)), "..", paths...)`.
└ @ Pkg.API /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Pkg/src/API.jl:454
ERROR: LoadError: MethodError: no method matching joinpath(::Nothing)
Closest candidates are:
  joinpath(!Matched::String, !Matched::String) at path.jl:217
  joinpath(!Matched::AbstractString) at path.jl:199
  joinpath(!Matched::AbstractString, !Matched::AbstractString) at path.jl:226
  ...
Stacktrace:
 [1] stat(::Nothing) at ./stat.jl:107
 [2] isdir(::Nothing) at ./stat.jl:303
 [3] top-level scope at none:0
 [4] include at ./boot.jl:317 [inlined]
 [5] include_relative(::Module, ::String) at ./loading.jl:1038
 [6] include at ./sysimg.jl:29 [inlined]
 [7] include_ifexists at ./client.jl:191 [inlined]
 [8] load_julia_startup() at ./client.jl:288
 [9] exec_options(::Base.JLOptions) at ./logging.jl:312
 [10] _start() at ./client.jl:421
in expression starting at /Users/cbinz/.julia/config/startup.jl:3

```

So, what’s the canonical way to check whether a package is installed, now?

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [August 10, 2018, 4:18am UTC](https://discourse.julialang.org/t/new-pkg-how-to-check-if-a-package-is-installed/13141/2 "2018-08-10T04:18:02Z")

</div>

`Pkg.status()`

---

<div class="post-metadata">

**Author:** ![Simon\_Bolland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simon_bolland/32/8920_2.png) [@Simon\_Bolland](https://discourse.julialang.org/u/Simon_Bolland)\
**Post date:** [August 10, 2018, 8:27am UTC](https://discourse.julialang.org/t/new-pkg-how-to-check-if-a-package-is-installed/13141/3 "2018-08-10T08:27:54Z")

</div>

I’d suggest

```julia
using Pkg
if in("OhMyREPL",keys(Pkg.installed()))
    @eval using OhMyREPL
else
    @warn("OhMyREPL not installed")
end

```

---

<div class="post-metadata">

**Author:** ![benibilme](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@benibilme](https://discourse.julialang.org/u/benibilme)\
**Post date:** [February 21, 2021, 5:56am UTC](https://discourse.julialang.org/t/new-pkg-how-to-check-if-a-package-is-installed/13141/4 "2021-02-21T05:56:50Z")

</div>

Pkg.status() returns “nothing”, can not be programmatically queried. Pkg.installed() gives ugly deprecated warnings.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [February 21, 2021, 11:09pm UTC](https://discourse.julialang.org/t/new-pkg-how-to-check-if-a-package-is-installed/13141/5 "2021-02-21T23:09:59Z")

</div>

```julia
using Pkg
function isinstalled(pk::AbstractString)
    return pk in [v.name for v in values(Pkg.dependencies())]
end

```
