# Disable automatic Pkg Garbage Collection

**URL:** https://discourse.julialang.org/t/disable-automatic-pkg-garbage-collection/104491
**Category:** General Usage
**Tags:** pkg
**Created:** [October 2, 2023, 8:27am UTC](https://discourse.julialang.org/t/disable-automatic-pkg-garbage-collection/104491 "2023-10-02T08:27:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [October 2, 2023, 8:27am UTC](https://discourse.julialang.org/t/disable-automatic-pkg-garbage-collection/104491/1 "2023-10-02T08:27:30Z")

</div>

Once upon a time Pkg didn’t ever delete old versions of packages that were no longer in use.  
Now it periodically does so automatically when doing other operations.  
I would like that to stop, because I have _so_ much hard-drive space.  
Even the fractional chance of me needing it again is worth keeping it around.

How do I disable this?  
I assume there is some method i need to monkey-patch, as i can’t find an environment variable in the docs.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [October 2, 2023, 10:16am UTC](https://discourse.julialang.org/t/disable-automatic-pkg-garbage-collection/104491/2 "2023-10-02T10:16:56Z")

</div>

I don’t think there’s a public way to do that at the moment:

> <https://github.com/JuliaLang/Pkg.jl/blob/3960c692bd4dd2b2eafc7699e8d0744f90756812/src/Pkg.jl#L781>

You can do `Pkg._auto_gc_enabled[] = false`, but that’s not reliable across different versions.

---

<div class="post-metadata">

### Author: ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)
#### Post date: [October 4, 2023, 8:20am UTC](https://discourse.julialang.org/t/disable-automatic-pkg-garbage-collection/104491/3 "2023-10-04T08:20:59Z")

</div>

Actually the problem can be more serious and a public API to set this would come in handy.

We had a scenario where we’d deploy an image with preinstalled Julia packates to create server instances in a cluster. As the image would get older, the `auto_gc` would kick in and introduce quite significant delays in the provisioning/startup time of the new instances.

We hacked it by using `Pkg._auto_gc_enabled[] = false` which worked (Julia 1.9 and 1.10).

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [October 4, 2023, 11:48am UTC](https://discourse.julialang.org/t/disable-automatic-pkg-garbage-collection/104491/4 "2023-10-04T11:48:50Z")

</div>

> <https://github.com/JuliaLang/Pkg.jl/pull/3642>
>
> This PR adds a \`JULIA\_PKG\_DISABLE\_AUTO\_GC\` environment variable to allow users t…o disable automatic garbage collection without reaching into Pkg's internals and setting \`\_auto\_gc\_enabled\[\] = false\` manually.
