# Change "current working module" from REPL

**URL:** <https://discourse.julialang.org/t/change-current-working-module-from-repl/53166>\
**Category:** General Usage\
**Tags:** question, repl, modules\
**Created:** [January 11, 2021, 4:32pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166 "2021-01-11T16:32:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cscherrer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cscherrer/32/7631_2.png) [@cscherrer](https://discourse.julialang.org/u/cscherrer)\
**Post date:** [January 11, 2021, 4:32pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166/1 "2021-01-11T16:32:35Z")

</div>

In package development, I often find myself needing to bring lots of things into scope, so I can run bits and pieces as if my package were running them. Something like

```julia
julia> using Foo # or some package I'm developing
julia> using Foo: f, g, h, j
julia> using Bar # a dependency of `Foo`

```

etc.

It’s a lot of typing, and it’s very error prone. It would be a lot easier if we had a way to change modules from the REPL. Is this possible? Or maybe there’s an easy way to automate what I’m currently doing?

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [January 11, 2021, 5:23pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166/2 "2021-01-11T17:23:19Z")

</div>

I don’t have an answer to your specific request, but if you only want to run a few isolated expressions, you can use `@eval M expr` to tell that you want to evaluate `expr` in module `M`. Or if it’s a larger piece of code that is written in a file, you can use `M.include(file)` or `Base.include(M, file)`.

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [January 11, 2021, 5:32pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166/3 "2021-01-11T17:32:12Z")

</div>

Also, since you are telling explicitly that you would like to change the working module _in the REPL_, I guess that you already know of how to do it in other environments. But anyway, I think that it is worth to comment that in VS Code you can choose the module where each file is meant to be run (also for “inline execution” with Alt+Enter etc.).

![image](https://global.discourse-cdn.com/julialang/original/3X/a/2/a244cc91a9efaf075e58196db474c1aea72a79b4.png)

---

<div class="post-metadata">

**Author:** ![cscherrer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cscherrer/32/7631_2.png) [@cscherrer](https://discourse.julialang.org/u/cscherrer)\
**Post date:** [January 11, 2021, 5:46pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166/4 "2021-01-11T17:46:46Z")

</div>

Really helpful suggestions, thank you @heliosdrm !

---

<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:** [January 11, 2021, 6:18pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166/5 "2021-01-11T18:18:29Z")

</div>

You could also give [this Gist](https://gist.github.com/pfitzseb/8fab21f09d6c15246d4a0960af3c65b1) a go:

```julia
julia> changeREPLmodule(Base)

Base> @ __MODULE__
Base

Base> Main.changeREPLmodule(Main)

Main> @ __MODULE__
Main

```

Juno also automatically changes the REPL module to the current module, while VSCode doesn’t (as pointed out above).

---

<div class="post-metadata">

**Author:** ![andreypopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreypopp/32/35877_2.png) [@andreypopp](https://discourse.julialang.org/u/andreypopp)\
**Post date:** [May 1, 2022, 10:18pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166/6 "2022-05-01T22:18:13Z")

</div>

> [@pfitzseb](#):
>
> You could also give [this Gist](https://gist.github.com/pfitzseb/8fab21f09d6c15246d4a0960af3c65b1) a go

This works beautifully! Unfortunately help mode and REPL completion doesn’t see that the module has changed.

---

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [February 14, 2024, 8:26pm UTC](https://discourse.julialang.org/t/change-current-working-module-from-repl/53166/7 "2024-02-14T20:26:42Z")

</div>

There’s now a built in way to do this - type the module name in the REPL and press `ALT-m`. Or use the `REPL.activate()` function.

Implemented in [REPL: allow switching contextual module by rfourquet · Pull Request #33872 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/33872). Just leaving a note here so that people finding this old discussion via google can find the modern solution.
