# Delete all packages installed in an environment

**URL:** <https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930>\
**Category:** General Usage\
**Tags:** question, environment\
**Created:** [July 11, 2024, 10:37pm UTC](https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930 "2024-07-11T22:37:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [July 11, 2024, 10:37pm UTC](https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930/1 "2024-07-11T22:37:36Z")

</div>

Suppose to try out a few things I create an environment as described [here](https://pkgdocs.julialang.org/v1/environments/). I install some packages and test the things I want to. Now I want to delete all the packages that I installed in this environment. Is there a command to do that? I believe that if a package that I installed in this trial environment was also installed in some other environment then it is not reinstalled on my computer. So, when I want to delete all the packages installed in this environment, I just want to delete those that were exclusively added for this environment. Is there a way to do that, without naming each individual package from `Project.toml`?

Thank you

---

<div class="post-metadata">

**Author:** ![savq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/savq/32/22063_2.png) [@savq](https://discourse.julialang.org/u/savq)\
**Post date:** [July 11, 2024, 11:02pm UTC](https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930/2 "2024-07-11T23:02:45Z")

</div>

There’s a [`]gc`](https://pkgdocs.julialang.org/v1/repl/#repl-gc) command in pkg mode that will delete “unreachable” packages.

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [July 12, 2024, 2:16am UTC](https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930/3 "2024-07-12T02:16:50Z")

</div>

Thank you @savq. Should this be called from the global environment after I have deleted the “temp” environment?

---

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [July 12, 2024, 2:39am UTC](https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930/4 "2024-07-12T02:39:50Z")

</div>

Note that this is done automatically every so often by the package manager. If you want to get rid of the packages immediately, then you probably want to call `Pkg.gc` as follows:

```julia
julia> using Pkg, Dates

julia> Pkg.gc(; collect_delay=Day(0))
      Active manifest files: 110 found
      Active artifact files: 455 found
      Active scratchspaces: 57 found
     Deleted no artifacts, repos, packages or scratchspaces

```

And yes, you can call it from the global environment after deleting the “temp” environment.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 12, 2024, 4:30am UTC](https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930/5 "2024-07-12T04:30:55Z")

</div>

To be clear, there’s no direct way to _uninstall_ a package by name precisely because another environment might still be using it, as you said. Deleting unwanted environments and `rm`-ing the package from kept environments is how you communicate to `Pkg.gc` that the package is safe to uninstall. If you’re just trying stuff out in a temporary environment, you can [make one](https://pkgdocs.julialang.org/v1/environments/#Temporary-environments) that Pkg deletes for you once you exit.

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [July 12, 2024, 3:08pm UTC](https://discourse.julialang.org/t/delete-all-packages-installed-in-an-environment/116930/6 "2024-07-12T15:08:45Z")

</div>

Thank you all. I appreciate your help.
