Suppose to try out a few things I create an environment as described here. 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?
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> 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.
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 that Pkg deletes for you once you exit.