Search code examples
govisual-studio-codevscode-debuggerapple-m1

GO VSCode debugger not working on Apple with M1 Chip


I can run the go files, but I can't debug them in vscode.

Error: "Failed to launch: could not launch process: can not run under Rosetta, check that the installed build of Go is right for your CPU architecture"


Solution

  • I ran into this as well after an upgrade to an Apple with an M1. There are several steps toward diagnosing the root cause of the issue. The first is to check the version of Go you've got installed.

    > go version
    go version go1.17.2 darwin/arm64
    

    If the version is not darwin/arm64 you've installed the wrong architecture for a Mac with an M1 chip. This is easy to do, since the default is darwin/amd64.

    If this is the issue, uninstall your current version of go and install the arm64 equivalent located here: https://golang.org/dl/

    Once the install is complete, it's time to verify two environment variables:

    In a terminal:

    > echo $GOOS 
    darwin
    
    > echo $GOARCH
    arm64
    

    If these are not set, go ahead and export them. I'd recommend adding them to your .zshrc or your equivalent.

    export GOOS=darwin
    export GOARCH=arm64
    

    Finally, in VS Code, launch your project and enter the command bar in order to re-install all of the Go: Install/Update tools:

    cmd + shift + p
    Go: Install/Update Tools
    

    This should allow you to run and debug successfully through VS Code.