# How to precompile all modules?

**URL:** <https://discourse.julialang.org/t/how-to-precompile-all-modules/4802>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 12, 2017, 12:25pm UTC](https://discourse.julialang.org/t/how-to-precompile-all-modules/4802 "2017-07-12T12:25:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [July 12, 2017, 12:25pm UTC](https://discourse.julialang.org/t/how-to-precompile-all-modules/4802/1 "2017-07-12T12:25:17Z")

</div>

Hello.

How can I precompile all modules in Julia from my first session instead of waiting for a while everytime Julia uses a new module?

Is there any fast way to install all Julia available packages or the most common ones without going one per one? Maybe a bunch of common useful packages.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [July 12, 2017, 12:39pm UTC](https://discourse.julialang.org/t/how-to-precompile-all-modules/4802/2 "2017-07-12T12:39:12Z")

</div>

I have this function in my .juliarc:

```julia
"Precompile all packages"
function precompile_pkgs end
try
    @eval using ProgressMeter
    @eval function precompile_pkgs()
        @showprogress for pkg in collect(keys(Pkg.installed()))
            if !isdefined(Symbol(pkg))
                info("Importing $(pkg)...")
                try (@eval import $(Symbol(pkg))) catch end
            end
        end
    end
catch
    function precompile_pkgs()
        for pkg in collect(keys(Pkg.installed()))
            if !isdefined(Symbol(pkg))
                info("Importing $(pkg)...")
                try (@eval import $(Symbol(pkg))) catch end
            end
        end
    end
end

```

which I got from [https://groups.google.com/d/msg/julia-users/N2let47lvSY/CNnlWFfhAwAJ](https://groups.google.com/d/msg/julia-users/N2let47lvSY/CNnlWFfhAwAJ)  
Then run `precompile_pkgs()` after a `Pkg.update()`.

I think JuliaPro bundles some packages. But anyway, just install the ones you need.

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [July 12, 2017, 2:46pm UTC](https://discourse.julialang.org/t/how-to-precompile-all-modules/4802/3 "2017-07-12T14:46:07Z")

</div>

I expected to see a single command 🙂  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [July 12, 2017, 3:04pm UTC](https://discourse.julialang.org/t/how-to-precompile-all-modules/4802/4 "2017-07-12T15:04:06Z")

</div>

Arguably it should be automatic:  
[https://github.com/JuliaLang/julia/issues/16409](https://github.com/JuliaLang/julia/issues/16409)

---

<div class="post-metadata">

**Author:** ![athulsudheesh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/athulsudheesh/32/9192_2.png) [@athulsudheesh](https://discourse.julialang.org/u/athulsudheesh)\
**Post date:** [April 16, 2018, 2:56am UTC](https://discourse.julialang.org/t/how-to-precompile-all-modules/4802/5 "2018-04-16T02:56:13Z")

</div>

This is so helpful! Thanks

---

<div class="post-metadata">

**Author:** ![pasha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pasha/32/3319_2.png) [@pasha](https://discourse.julialang.org/u/pasha)\
**Post date:** [April 16, 2018, 3:30am UTC](https://discourse.julialang.org/t/how-to-precompile-all-modules/4802/6 "2018-04-16T03:30:16Z")

</div>

One modification that makes it work here, is that the command doesn’t seemed to hang up on `Compat.jl`.

So I modified the loop to exclude Compat, as below:

```julia
    function precompile_pkgs()
        for pkg in collect(keys(Pkg.installed()))
            if !isdefined(Symbol(pkg)) && pkg != "Compat.jl"
                info("Importing $(pkg)...")
                try (@eval import $(Symbol(pkg))) catch end
            end
        end
    end

```

Also that bit with `ProgressMeter` doesn’t work, so at some point I’ll just remove that cleverness. But the function does indeed make everything precompile.
