# Tip: macro to install/use package in temporary environment

**URL:** <https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190>\
**Category:** General Usage\
**Created:** [August 25, 2023, 2:12pm UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190 "2023-08-25T14:12:39Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 28, 2023, 1:53pm UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190/21 "2023-08-28T13:53:20Z")

</div>

> [@jishnub](#):
>
> `julia> push!(Base.LOAD_PATH, mktempdir())`

That’s nice, but what is the criterium for which is the environment selected by default when one types “`o`” ?

With `push!` the temporary environment goes to the end of the list and it is still the default one chosen (which is nice).

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [August 28, 2023, 1:56pm UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190/22 "2023-08-28T13:56:48Z")

</div>

Aah, I guess now `push!` is indeed better for temp env! It wasn’t the case until recently, and most likely I chose `insert!(2)` originally because of default selection in the dialog. After [try\_prompt\_pkg\_add: on "other" preselect the first non-default env by aplavin · Pull Request #3473 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/pull/3473), it preselects the first non-default env, and `push!` works just as well!

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 28, 2023, 2:05pm UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190/23 "2023-08-28T14:05:53Z")

</div>

Is the possibility of _always_ having a temporary environment in that list considered?

I don’t see any downside, and it would suggesting a good package management workflow for casual users much simpler.

---

<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:** [September 26, 2023, 5:55am UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190/24 "2023-09-26T05:55:53Z")

</div>

> ```julia
> (y/n/o) [y]: 
> 
> ```

when this feature was added.  
@StefanKarpinski and I were talking about having a `y/n/o/t` where `t` would create and activate a temp enviroment.  
Push back was that it would be too complicated.

And I solved my original need by just creating TestEnv.jl  
since I was mostly wanting to use that to test things interactively

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [September 26, 2023, 12:12pm UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190/25 "2023-09-26T12:12:55Z")

</div>

Both this feature and TestEnv are great! I use this `[o]` autoinstall to temp dir way more than TestEnv though, mostlty not for package testing but for running some quick computation in the REPL or playing with an interesting package.

---

<div class="post-metadata">

**Author:** ![aminsadeghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminsadeghi/32/22853_2.png) [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Post date:** [September 27, 2023, 1:07pm UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190/26 "2023-09-27T13:07:04Z")

</div>

Why is the “2” important?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [September 27, 2023, 3:02pm UTC](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190/27 "2023-09-27T15:02:44Z")

</div>

Not really, it is just that I want that the temporary environment is the one chosen by default when the options are shown, and that depends on the order of the entries of the path.

[Previous page](https://discourse.julialang.org/t/tip-macro-to-install-use-package-in-temporary-environment/103190.md?page=1)
