# Environment variables

**URL:** <https://discourse.julialang.org/t/environment-variables/58760>\
**Category:** New to Julia\
**Tags:** environment\
**Created:** [April 7, 2021, 3:03pm UTC](https://discourse.julialang.org/t/environment-variables/58760 "2021-04-07T15:03:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laco\_Kovac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laco_kovac/32/20684_2.png) [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Post date:** [April 7, 2021, 3:03pm UTC](https://discourse.julialang.org/t/environment-variables/58760/1 "2021-04-07T15:03:45Z")

</div>

I am on Windows (if that matters).  
Inside my program i.e. myApp.run() I am checking content of a certain env. variable e.g.

`env_var = get(ENV, "XYZ", "8073")`

From command prompt/terminal in VS Code, before I execute julia, I call

`set XYZ=5555`

but then inside julia, inside myApp.run(), env\_var is set to default 8073, which means it didn’t find any XYZ env. variable. And when I do

`println(ENV)`

inside that function, XYZ is not listed. However, other env. variables seem to be there.

How should I understand this? What variables are listed, and why is not my XYZ not there? Is there special julia command line argument to enforce env. variable?

Thank you.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [April 7, 2021, 3:13pm UTC](https://discourse.julialang.org/t/environment-variables/58760/2 "2021-04-07T15:13:47Z")

</div>

Did you also export the variable? In Bash (not POSIX): `export xyz=1`

By the way, you can use `x in keys(ENV)` and get via `ENV[x]` since ENV is a Dict

EDIT: This advise didn’t take into account that you’re on Windows. Then, I don’t have an idea what the problem could be

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [April 7, 2021, 3:22pm UTC](https://discourse.julialang.org/t/environment-variables/58760/3 "2021-04-07T15:22:49Z")

</div>

Sorry for this small advertisement, but since you said, that you are checking variables inside your application, I presume you want to store some secrets in `ENV` and use them later. If it is a case, you can use [ConfigEnv.jl](https://github.com/Arkoniak/ConfigEnv.jl). I am finalizing documentation, but main idea is that you save necessary environment data in `.env` (or any other file of your choice), put it in `.gitignore` and use it to populate `ENV` with `dotenv()` command in your application. It’s very simple and working on all platforms.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 7, 2021, 3:33pm UTC](https://discourse.julialang.org/t/environment-variables/58760/4 "2021-04-07T15:33:21Z")

</div>

> [@Laco\_Kovac](#):
>
> From command prompt/terminal in VS Code, before I execute julia, I call
> 
> `set XYZ=5555`

How do you execute julia in this scenario exactly?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 7, 2021, 4:05pm UTC](https://discourse.julialang.org/t/environment-variables/58760/5 "2021-04-07T16:05:44Z")

</div>

In VSCode:  
File → Preferences → Settings

In “Search settings” enter:  
terminal.integrated.env

You find a entry called “Terminal › Integrated › Env: Windows”

Click on  
“Edit in settings.json”

Add e.g.:

```julia
    "terminal.integrated.env.windows": {        
        "TEST": "XXX"
    }

```

Environment variable TEST is now propagated into any terminal you open in VSCode, including the Julia REPL started with View → Command Palette… “Julia: Start REPL”

---

<div class="post-metadata">

**Author:** ![Laco\_Kovac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laco_kovac/32/20684_2.png) [@Laco\_Kovac](https://discourse.julialang.org/u/Laco_Kovac)\
**Post date:** [April 8, 2021, 7:18am UTC](https://discourse.julialang.org/t/environment-variables/58760/6 "2021-04-08T07:18:03Z")

</div>

> [@oheil](#):
>
> terminal.integrated.env

Yes, thank you!!

I also found out why SET command didn’t work for me.  
In VS Code, terminal is powershell, not [command.com](http://command.com), thus SET XYZ=5555 does something very different there. Command to set env. variable there is

`$Env:XYZ="5555"`

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 8, 2021, 7:20am UTC](https://discourse.julialang.org/t/environment-variables/58760/7 "2021-04-08T07:20:59Z")

</div>

> [@Laco\_Kovac](#):
>
> In VS Code, terminal is powershell

And than you need to start julia from inside this powershell, which isn’t the typical way how the REPL is started in VSCode.
