# Setting environment variable in VS Code debugger

**URL:** https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864
**Category:** VS Code
**Tags:** debugging
**Created:** [April 24, 2023, 2:58pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864 "2023-04-24T14:58:29Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Yue-Zhengyuan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yue-zhengyuan/32/220439_2.png) [@Yue-Zhengyuan](https://discourse.julialang.org/u/Yue-Zhengyuan)
#### Post date: [April 24, 2023, 2:58pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/1 "2023-04-24T14:58:29Z")

</div>

How to set environment variables in VS Code debugger in launch.json for Julia? For Python, the env var can be set by the “env” property:

```julia
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "env": {"MYVAR": "value"}
        },
    ]
}

```

Then the env var “MYVAR” is added to the current debugging session. However, when I try to do the same for Julia, I get the error “Property env is not allowed.” Instead intellisense suggest a property called “juliaEnv” (Absolute path to the Julia environment), which seems to be an entirely different thing. What is the correct way to do this?

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [April 24, 2023, 5:24pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/2 "2023-04-24T17:24:20Z")

</div>

Unfortunately not yet implemented, see [here](https://github.com/julia-vscode/julia-vscode/issues/1048).

---

<div class="post-metadata">

### Author: ![Yue-Zhengyuan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yue-zhengyuan/32/220439_2.png) [@Yue-Zhengyuan](https://discourse.julialang.org/u/Yue-Zhengyuan)
#### Post date: [April 25, 2023, 1:13am UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/3 "2023-04-25T01:13:18Z")

</div>

Is there any (relatively simple) workaround?

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [April 25, 2023, 5:49am UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/4 "2023-04-25T05:49:43Z")

</div>

Can’t really think of any… I don’t think it would be difficult to properly add to the extension, if someone wanted to give it a go.

I think it should be enough to add support for `env` [here](https://github.com/julia-vscode/julia-vscode/blob/af6314c972a3cad4cb952033fff2035e446f3980/package.json#L1329) (ideally copy that from how another language does it), and then make sure that the values from `args.env` get added [here](https://github.com/julia-vscode/julia-vscode/blob/af6314c972a3cad4cb952033fff2035e446f3980/src/debugger/juliaDebug.ts#L242) and [here](https://github.com/julia-vscode/julia-vscode/blob/af6314c972a3cad4cb952033fff2035e446f3980/src/debugger/juliaDebug.ts#L313).

---

<div class="post-metadata">

### Author: ![Yue-Zhengyuan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yue-zhengyuan/32/220439_2.png) [@Yue-Zhengyuan](https://discourse.julialang.org/u/Yue-Zhengyuan)
#### Post date: [April 25, 2023, 3:17pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/5 "2023-04-25T15:17:41Z")

</div>

The Python extension has [this](https://github.com/microsoft/vscode-python/blob/main/package.json#L1297) in its package.json, which can be directly copied to Julia; it not only supports “env”, but also “envFile” which allows users to input the env variables from a file. But unfortunately I am not familiar with the making of a VS Code extension, so may not be able to help make a pull request…

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [April 25, 2023, 3:57pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/6 "2023-04-25T15:57:52Z")

</div>

One workaround would be to set the environment variables and start Julia in a regular VSCode terminal session, then connect to that session (via the “Connect external REPL” command).

---

<div class="post-metadata">

### Author: ![Yue-Zhengyuan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yue-zhengyuan/32/220439_2.png) [@Yue-Zhengyuan](https://discourse.julialang.org/u/Yue-Zhengyuan)
#### Post date: [April 30, 2023, 2:07am UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/7 "2023-04-30T02:07:08Z")

</div>

I am thinking another workaround by using the `preLaunchTask` in `launch.json`. I add the following task to the `task.json` file:

```json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "set_envvar",
            "type": "shell",
            "command": "export MYVAR=\"value\""
        },
    ]
}

```

Then I add `"preLaunchTask": "set_envvar"` to the `launch.json`. But it does not seem to work. I get the following output in VS Code terminal:

```julia
 * Executing task: export MYVAR="value"

 * Terminal will be reused by tasks, press any key to close it. 

 * Executing task: # my debug task

```

So I guess that the terminal forgets the first task after the pre-launch task finished? Is it actually OK to set envvars in this way?

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [May 1, 2023, 4:09pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/8 "2023-05-01T16:09:34Z")

</div>

That won’t work. We spawn a new Julia process in the extension, and we (the extension) control what env vars are passed to it, so we’ll have to just implement that.

---

<div class="post-metadata">

### Author: ![convexhull](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@convexhull](https://discourse.julialang.org/u/convexhull)
#### Post date: [June 17, 2024, 1:25am UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/9 "2024-06-17T01:25:52Z")

</div>

Has there been any progress on this?

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [June 17, 2024, 5:43am UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/10 "2024-06-17T05:43:54Z")

</div>

I’m in the process of [rewriting](https://github.com/julia-vscode/julia-vscode/pull/3616) much of the debugger integration, and as part of that I’ll fix this.

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [July 5, 2024, 10:22pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/11 "2024-07-05T22:22:11Z")

</div>

Just FYI, the preview version of the extension now supports this.

---

<div class="post-metadata">

### Author: ![hapopo](https://avatars.discourse-cdn.com/v4/letter/h/5daacb/32.png) [@hapopo](https://discourse.julialang.org/u/hapopo)
#### Post date: [August 21, 2024, 9:28am UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/12 "2024-08-21T09:28:38Z")

</div>

when you write “supports this” you mean that you can now change environment variables? if so, will you please elaborate a bit on how can one do that?

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [August 21, 2024, 6:14pm UTC](https://discourse.julialang.org/t/setting-environment-variable-in-vs-code-debugger/97864/13 "2024-08-21T18:14:01Z")

</div>

Take a look at [Debugging in Visual Studio Code](https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes), and in particular the `env` attribute which we now support.
