Environment variables in Linux are supported now in VSCode (although I don't know since when or which version exactly). I have VSCode for Linux 1.73.1.

You can now use the following (just like in the question above):

{
    "java.home": "${env:HOME}/.sdkman/candidates/java/8.0.222.hs-adpt/"
}
Answer from Hechi on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › reference › variables-reference
Variables reference
November 3, 2021 - The predefined variables are supported in a select number of setting keys in settings.json files such as the terminal cwd, env, shell and shellArgs values.
Discussions

Using environmental variable in settings.json
settings.json in this example literally only stores the string literal for that key. JSON inherently has no logic. It's up to whatever extension that is ingesting the value to do any potential interpolation. More on reddit.com
🌐 r/vscode
2
2
January 2, 2025
How to Set up Environment Variables in "launch.json" Configuration When Using GDB Integration in VS Code - Unix & Linux Stack Exchange
The purpose of this setup is to use GDB integration in vscode. In particular, I specified the following pair to ensure all environment variables set up in my bash session in terminal of vscode are inherited when debugging: "externalConsole": false. I also notice that there is a pair named ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 16, 2022
Variables Support in Setting.json
VS Code settings in Setting.json doesn't support variables(such as ${userHome},${env:USERNAME}). It spoils the experience. Some plugins(such as Run Terminal Command) support environment variables in settings.json. More on github.com
🌐 github.com
2
February 16, 2024
Setting environment variable in VS Code debugger
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: { "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": ... More on discourse.julialang.org
🌐 discourse.julialang.org
12
0
April 24, 2023
🌐
Steve Kinney
stevekinney.com › courses › visual studio code › controlling settings with environment variables in visual studio code
Controlling Settings with Environment Variables in Visual Studio Code | Visual Studio Code | Steve Kinney
March 17, 2026 - You can reference environment variables in settings.json using the ${env:VARIABLE_NAME} syntax. { "terminal.integrated.defaultProfile.windows": "${env:WSL_DISTRO_NAME}", // Use WSL distro name as default terminal profile on Windows ...
🌐
Orchestra
getorchestra.io › guides › using-os-environ-with-local-settings-in-vs-code-settings-json
Using os.environ with Local Settings in VS Code settings.json | Orchestra
March 22, 2025 - By leveraging os.environ, you can reference environment variables from within your code or settings files, keeping your sensitive information out of reach from version control. VS Code allows developers to customize their workspace configuration through settings.json.
🌐
Reddit
reddit.com › r/vscode › using environmental variable in settings.json
r/vscode on Reddit: Using environmental variable in settings.json
January 2, 2025 -

Could anyone tell me why this doesn't work?

{
    "roc-lang.language-server.exe": "${env:ROC_LANGUAGE_SERVER_PATH}",
    // If you'd like to format Roc files on save
    "editor.formatOnSave": true
}

This is in the workspace settings.json for a project. When I look at the plugin's output, it's treating that exact string as the path, rather than resolving it to the value of the environmental variable. A few other things to note:

  1. If I instead use the literal string that is the value of the variable, it works fine.

  2. I am able to echo that variable in vs code's terminal, so I know it's available.

  3. I am on on linux with a reasonably recent version of vs code.

Thanks.

EDIT: Maybe this is just a limitation of the roc language plugin, that it isn't programmed to resolve the variable?

🌐
Visual Studio Code
code.visualstudio.com › remote › advancedcontainers › environment-variables
Environment variables
November 3, 2021 - Dockerfile or image: Add the containerEnv property to devcontainer.json to set variables that should apply to the entire container or remoteEnv to set variables for VS Code and related sub-processes (terminals, tasks, debugging, etc.):
🌐
Visual Studio Code
code.visualstudio.com › docs › python › environments
Python environments in VS Code
November 3, 2021 - When you assign an environment to a project, the extension writes to your workspace settings (.vscode/settings.json):
Find elsewhere
Top answer
1 of 3
4

Here is an example, you set the value in the environment block.

    {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "g++ - (GDB 9.2) Build and debug active file with RepoCodeInspection",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/bin/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [
            {
                "description": "same as commands below by using 'setenv ...",
                "info": "cant debug b/c of libBase/libRecipe now requiring dependency to boost for stacktrace dumps",
                "name": "LD_LIBRARY_PATH",
                "value": "/libs/:./"
            }
        ],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "logging": {
            "trace": false,
            "traceResponse": false
        },
        "preLaunchTask": "RepoCodeInspection",
        
    },
    {
        "name": "g++ - (GDB 9.2) Attach to a running process",
        "type": "cppdbg",
        "request": "attach",
        "processId":"${command:pickProcess}",
        "program": "${fileDirname}/bin/${fileBasenameNoExtension}",
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "logging": {
            "trace": false,
            "traceResponse": false
        },
        "preLaunchTask": "RepoCodeInspection",
       
    },
]

}

2 of 3
3

To set multiple environment variables, use comma-separated "name", "value" pairs.

Example:

"environment": [{"name": "LD_LIBRARY_PATH", "value": "/ld/library/path/"},
                {"name": "CUDA_VISIBLE_DEVICES", "value": "0"}
               ]
🌐
GitHub
github.com › microsoft › vscode › issues › 205327
Variables Support in Setting.json · Issue #205327 · microsoft/vscode
February 16, 2024 - VS Code settings in Setting.json doesn't support variables(such as ${userHome},${env:USERNAME}). It spoils the experience. Some plugins(such as Run Terminal Command) support environment variables in settings.json.
Author   xiaoxstz
🌐
Julia Programming Language
discourse.julialang.org › tooling › vs code
Setting environment variable in VS Code debugger - VS Code - Julia Programming Language
April 24, 2023 - 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: { "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” i...
🌐
GitHub
github.com › microsoft › vscode › issues › 114515
`${env:VARIABLE}` not work sometimes in `settings.json` · Issue #114515 · microsoft/vscode
January 18, 2021 - So why VS Code did not recognize the JAVA_HOME variable? ... In settings.json, set java.configuration.maven.userSettings to ${env:M2_HOME}\\conf\\settings.xml, and M2_HOME="D:\Program Files\maven".
Author   woobhurk
🌐
GitHub
github.com › Microsoft › vscode › issues › 43351
Possible to support variables in settings.json? · Issue #43351 · microsoft/vscode
Maven stores downloaded JARs to ~/.m2. On Linux ~ expands to /home/username, while on MacOS it expands to /Users/user.name. Now if I could use an environment variable in the settings.json file, I could keep the setting platform agnostic in the form of ${env:HOME}/.m2/path/to/lombok.jar
Author   ghost
🌐
GitHub
github.com › microsoft › vscode › issues › 8147
Support using environment variables in settings.json · Issue #8147 · microsoft/vscode
July 6, 2022 - It would be nice to be able to use environment variables in paths in settings.json, this is not possible in build 1.2.1 and older. In my scenariio I`m syncing VS Code settings between computers, for example: // Specifies the path to a PowerShell Script Analyzer settings file. Use either an absolute path (to override the default settings for all projects) or use a path relative to your workspace. "powershell.scriptAnalysis.settingsPath": "%home%.vscode\PSScriptAnalyzerSettings.psd1"
Author   janegilring
🌐
GitHub
github.com › golang › vscode-go › issues › 2395
Environment Variable interpolation in settings.json · Issue #2395 · golang/vscode-go
August 5, 2022 - # .vscode/settings.json { "go.testEnvVars": { "FOOBAR": "foo ${env:BAR}" }, } Describe the solution you'd like Strings of the form ${env:FOOBAR} should be replaced with the environment variable value. Describe alternatives you've considered You'd think this should be implemented in VSCode but that's not going to happen.
Author   hrobertson
🌐
Visual Studio Code
code.visualstudio.com › docs › configure › settings
User and workspace settings
November 3, 2021 - The gear icon alongside the setting (⇧F9 (Windows, Linux Shift+F9)) opens a context menu with options to reset a setting to its default value, and to copy the setting ID, copy a JSON name-value pair, or copy the settings URL. ... A settings URL enables you to navigate directly to a specific setting in the Settings editor from the browser. The URL is in the format vscode://settings/<settingName>, where <settingName> is the ID of the setting you want to navigate to.
🌐
Medium
reuvenharrison.medium.com › using-visual-studio-code-to-debug-a-go-program-with-environment-variables-523fea268271
Debugging go in vscode with environment variables | by Reuven Harrison | Medium
August 30, 2020 - Debugging go in vscode with environment variables When running tests in vscode you often need environment variables, some of which may have json values. Option 1: settings.json Open settings.json and …
Top answer
1 of 15
123

Assuming you mean for a debugging session(?) then you can include a env property in your launch configuration.

If you open the .vscode/launch.json file in your workspace or select Debug > Open Configurations then you should see a set of launch configurations for debugging your code. You can then add to it an env property with a dictionary of string:string.

Here is an example for an ASP.NET Core app from their standard web template setting the ASPNETCORE_ENVIRONMENT to Development :

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Launch (web)",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      // If you have changed target frameworks, make sure to update the program path.
      "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/vscode-env.dll",
      "args": [],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
      "internalConsoleOptions": "openOnSessionStart",
      "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
          "command": "cmd.exe",
          "args": "/C start ${auto-detect-url}"
        },
        "osx": {
          "command": "open"
        },
        "linux": {
          "command": "xdg-open"
        }
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceFolder}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:pickProcess}"
    }
  ]
}

2 of 15
73

You can load an environment file by setting the envFile property like this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch",
      "type": "go",
      "request": "launch", 
      "mode": "debug",
      "remotePath": "",
      "port": 2345,
      "host": "127.0.0.1",
      "program": "${workspaceFolder}",
      "envFile": "${workspaceFolder}/.env", // HERE
      "args": [], 
      "showLog": true
    }
  ]
}

Place the .env file in your folder and add vars like this:

KEY1="TEXT_VAL1"
KEY2='{"key1":val1","key2":"val2"}'

Further Reading: Debugging go in vscode with environment variables

🌐
Reddit
reddit.com › r/vscode › my settings.json file can't read variables in my .env file.
r/vscode on Reddit: my settings.json file can't read variables in my .env file.
January 27, 2023 -

I am trying to override the default python interpreter for a specific workspace. I have created a .vscode directory in the folder with the following two files:

settings.json:

{
    "python.envFile": "${workspaceFolder}/.vscode/.env",
    "python.defaultInterpreterPath": "${env:MY_PYTHON_PATH}/bin/python",
}

.vscode/.env:

MY_PYTHON_PATH=/path/to/my/python/interpreter

But the python interpreter is actually getting set to /bin/python - which implies that ${env:MY_PYTHON_PATH} is just empty.

Any ideas what is going wrong here?

🌐
Reddit
reddit.com › r/vscode › user-defined variables in settings.json and tasks.json
r/vscode on Reddit: user-defined variables in settings.json and tasks.json
December 5, 2020 - { "version": "2.0.0", /* options can be in any legal place ... reading env:varname from it will be always blank*/ "options": { "env": { "compiler" : "cl.exe", "clang" : "${config:dbj.clang_x64}" } }, "tasks": [ { "type": "shell", "label": "test_task", /* second echo is blank result `[]` */ "command": "echo config:cdbj.clang_x64 = [${config:dbj.clang_x64}] & echo env:clang = [${env:clang}]", "detail": "testing user defined variables from tasks.json", "group": { /* this is ok to be added to every task, this also shows normal list of tasks with no repetitions after CTRL+SHIFT+B */ "kind": "build"