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.