Skip to content

Instantly share code, notes, and snippets.

@extremecoders-re
Last active June 26, 2025 16:07
Show Gist options
  • Save extremecoders-re/9e8e515aed82d95c205df45dffa8f5fd to your computer and use it in GitHub Desktop.
Save extremecoders-re/9e8e515aed82d95c205df45dffa8f5fd to your computer and use it in GitHub Desktop.
Using VSCode with a conda go environment
$ conda create -n goenv go
$ conda activate goenv
(goenv) $ conda install -c conda-forge gxx_linux-64  # Required for the vscode go extension

Note the current goroot path

(goenv) $ go env GOROOT
/home/ec/miniconda3/envs/go/go

Add the path to vscode settings.json (Workspace or Global)

For workspace: config is saved in .vscode/settings.json

{
    "go.goroot": "/home/ec/miniconda3/envs/go/go",
}

Next install the Go plugin for VScode. It will prompt to install a few tools. Click on "Install All". However the installation of some tool will surely fail which needs to be installed manually like.

(goenv) $ go install -v github.com/cweill/gotests/[email protected]
(goenv) $ go install -v github.com/haya14busa/goplay/cmd/[email protected]
(goenv) $ go install -v github.com/go-delve/delve/cmd/dlv@latest
(goenv) $ go install -v honnef.co/go/tools/cmd/staticcheck@latest
(goenv) $ go install -v golang.org/x/tools/gopls@latest

The exact tools which failed and the corresponding command to install them can be found in the Output panel in VScode.

References

@extremecoders-re
Copy link
Author

extremecoders-re commented Apr 13, 2024

On windows with conda installed from scoop

{
    "go.goroot": "C:/Users/Administrator/scoop/apps/miniconda3/current/envs/go1.22",
    "terminal.integrated.env.windows": {
        "GOROOT": "C:/Users/Administrator/scoop/apps/miniconda3/current/envs/go1.22"
    },
}

When running vscode from a preactivated conda go environment

{
    "go.goroot": "${env:CONDA_PREFIX}/go",
    "terminal.integrated.env.windows": {
        "GOROOT": "${env:CONDA_PREFIX}\\go",
        "PATH": "${env:CONDA_PREFIX}/bin;${env:PATH}"
    },
}

This works as the environment variable is set to the current environment CONDA_PREFIX=C:\Users\Administrator\scoop\apps\miniconda3\current\envs\go.

Otherwise you can hardcode the path to avoid launching vscode from the terminal.

Important

If this doesn't work close ALL instances of VScode and try again.

References

@extremecoders-re
Copy link
Author

Go installed from pixi on Linux

Go was installed locally per project with pixi add go.

{
    "go.goroot": "/home/ec/workspace/shred-decoder/.pixi/envs/default/go"
}

@extremecoders-re
Copy link
Author

extremecoders-re commented May 3, 2025

Another way with conda installed from scoop

This solves the issue:

go: cannot find GOROOT directory: 'go' binary is trimmed and GOROOT is not set

conda activate <env_name>
which go
conda conda env config vars set GOROOT="C:/Users/Administrator/scoop/apps/miniconda3/current/envs/<env_name>/go"

The PATH can also be appended this way

conda conda env config vars set PATH="C:\Users\Administrator\go\bin;%PATH%"

Warning

Apparently setting the PATH this way doesn't work. The %PATH% variable is not expanded.

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables

@extremecoders-re
Copy link
Author

Issue with VSCode unable to detect Go even when launched from a conda activated environment

settings.json

    "terminal.integrated.env.windows": {
        "GOROOT": "C:\\Users\\Administrator\\scoop\\apps\\miniconda3\\current\\envs\\asi-client\\go",
        "PATH": "C:/Users/Administrator/scoop/apps/miniconda3/current/envs/asi-client/bin;${env:PATH}"
    },
    "go.toolsEnvVars": {
        "GOROOT": "C:\\Users\\Administrator\\scoop\\apps\\miniconda3\\current\\envs\\asi-client\\go",
        "PATH": "C:/Users/Administrator/scoop/apps/miniconda3/current/envs/asi-client/bin;${env:PATH}"
    },
    "go.terminal.activateEnvironment": true,
    "go.alternateTools": {
        "go": "C:/Users/Administrator/scoop/apps/miniconda3/current/envs/asi-client/bin/go.exe",
        "dlv": "dlv"
    }

The core issue is the env variables (including PATH) set by conda at environment activation in the command prompt session is not correctly inherited by the VSCode process, even though launched from the same terminal. Cursor does not have the issue however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment