### Install Go Version With Architecture Override Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Example of installing an older Go version on an Apple M1 by overriding the architecture to 'amd64' using ASDF_GOLANG_OVERWRITE_ARCH. ```bash > ASDF_GOLANG_OVERWRITE_ARCH=amd64 asdf install golang 1.15.8 Platform 'darwin' supported! % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 116M 100 116M 0 0 98.6M 0 0:00:01 0:00:01 --:--:-- 98.6M verifying checksum /Users//.asdf/downloads/golang/1.15.8/archive.tar.gz: OK checksum verified ``` -------------------------------- ### Default Go Get Packages Configuration Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Configure default packages to be installed with 'go get -u $PACKAGE' after a new Go version is installed. List one package per line. Comments are allowed. ```bash // allows comments github.com/Dreamacro/clash github.com/jesseduffield/lazygit ``` -------------------------------- ### Install Go Version Without Architecture Override Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Example of attempting to install an older Go version on an Apple M1, which fails due to the architecture mismatch without override. ```bash > asdf install golang 1.15.8 Platform 'darwin' supported! URL: https://dl.google.com/go/go1.15.8.darwin-arm64.tar.gz returned status 404 ``` -------------------------------- ### List Available and Installed Go Versions Source: https://context7.com/asdf-community/asdf-golang/llms.txt Lists all installable Go versions from the upstream repository and locally installed versions. Filters out older releases and release candidates. ```bash # List all available Go versions (output piped for readability) asdf list all golang | tr ' ' '\n' | tail -10 # 1.21.10 # 1.21.11 # 1.22.0 # 1.22.1 # 1.22.2 # 1.22.3 # 1.22.4 # 1.22.5 # 1.23.0 # 1.23.1 # List locally installed versions asdf list golang # *1.22.3 # 1.21.0 ``` -------------------------------- ### Reshim Go Binaries Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Run 'asdf reshim golang' after installing packages with 'go get' or 'go install' to update shims. ```bash asdf reshim golang ``` -------------------------------- ### Add and List asdf-golang Plugin Source: https://context7.com/asdf-community/asdf-golang/llms.txt Installs the asdf-golang plugin and verifies its registration. This command only needs to be run once per machine. ```bash # Add the plugin asdf plugin add golang https://github.com/asdf-community/asdf-golang.git # Verify the plugin is registered asdf plugin list # golang ``` -------------------------------- ### Install Default Go Packages Automatically Source: https://context7.com/asdf-community/asdf-golang/llms.txt Automatically installs packages listed in `~/.default-golang-pkgs` when a new Go version is installed. Supports custom file locations via `ASDF_GOLANG_DEFAULT_PACKAGES_FILE`. Remember to reshim after installation. ```bash # Create the default packages file cat > ~/.default-golang-pkgs <<'EOF' // CLI tools installed automatically with every new Go version github.com/jesseduffield/lazygit@latest github.com/Dreamacro/clash@latest golang.org/x/tools/gopls@latest // LSP server github.com/go-delve/delve/cmd/dlv@latest EOF # Now install a Go version — packages are installed automatically asdf install golang 1.22.3 # Installing go1.22.3 ... # Installing github.com/jesseduffield/lazygit@latest go pkg... SUCCESS # Installing github.com/Dreamacro/clash@latest go pkg... FAIL # Installing golang.org/x/tools/gopls@latest go pkg... SUCCESS # Use a custom file location ASDF_GOLANG_DEFAULT_PACKAGES_FILE=~/dotfiles/go-packages asdf install golang 1.22.3 # After install, reshim to register new binary shims asdf reshim golang ``` -------------------------------- ### Install and Manage Go Versions with asdf-golang Source: https://context7.com/asdf-community/asdf-golang/llms.txt Installs specific or the latest Go versions, sets them globally, and verifies the installation. Supports architecture overrides for cross-platform builds. ```bash # Install a specific Go version asdf install golang 1.22.3 # Install the latest stable Go version asdf install golang latest # Install an older version for Apple M1 using an amd64 build ASDF_GOLANG_OVERWRITE_ARCH=amd64 asdf install golang 1.15.8 # Set the installed version globally asdf global golang 1.22.3 # Verify active version go version # go version go1.22.3 linux/amd64 ``` -------------------------------- ### Discover Binary Paths for Shimming Source: https://context7.com/asdf-community/asdf-golang/llms.txt Identifies directories containing executables to be shimmed by asdf. `asdf-golang` exposes `bin` (for `go install` packages) and `go/bin` (for `go` and `gofmt`). Reshim after installing new tools. ```bash # The plugin returns: "bin go/bin" # This means asdf creates shims for all executables under: # ~/.asdf/installs/golang//bin/ # ~/.asdf/installs/golang//go/bin/ # After installing a tool with go install, reshim to create its shim: go install github.com/rakyll/hey@latest asdf reshim golang # Verify the shim exists and resolves correctly which hey # ~/.asdf/shims/hey hey --help ``` -------------------------------- ### Add asdf-golang Plugin Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Use this command to add the golang plugin to your asdf installation. ```bash asdf plugin add golang https://github.com/asdf-community/asdf-golang.git ``` -------------------------------- ### Find Latest Stable Go Version Source: https://context7.com/asdf-community/asdf-golang/llms.txt Retrieves the latest stable Go version, optionally filtered by a version prefix. Useful for scripting automated installations. ```bash # Get the overall latest stable version asdf latest golang # 1.23.1 # Get the latest stable patch in the 1.21.x line asdf latest golang 1.21 # 1.21.11 # Use in scripting LATEST=$(asdf latest golang) asdf install golang "$LATEST" asdf global golang "$LATEST" ``` -------------------------------- ### Uninstall a Specific Go Version Source: https://context7.com/asdf-community/asdf-golang/llms.txt Removes the installation directory for a specified Go version. Ensures write permissions are granted before deletion to prevent errors. Use `asdf list golang` to confirm removal and `asdf global` to switch versions if needed. ```bash # Uninstall a specific Go version asdf uninstall golang 1.21.0 # Confirm it is removed asdf list golang # *1.22.3 # Switch global version if the uninstalled version was active asdf global golang 1.22.3 ``` -------------------------------- ### Override Go Architecture for Cross-Compilation Source: https://context7.com/asdf-community/asdf-golang/llms.txt Use `ASDF_GOLANG_OVERWRITE_ARCH` to specify a target architecture for Go installations, enabling cross-architecture builds. Supported values include `amd64`, `386`, `armv6l`, `arm64`, `ppc64le`, `loong64`, `riscv64`. ```bash # Supported arch values: amd64, 386, armv6l, arm64, ppc64le, loong64, riscv64 # Install amd64 Go on an Apple M1 (arm64) host for an older version ASDF_GOLANG_OVERWRITE_ARCH=amd64 asdf install golang 1.15.8 # Platform 'darwin' supported! # URL: https://dl.google.com/go/go1.15.8.darwin-amd64.tar.gz # checksum verified # Persist the override in your shell profile for a project that requires it export ASDF_GOLANG_OVERWRITE_ARCH=amd64 asdf install golang 1.15.8 ``` -------------------------------- ### Download Go Archive with Checksum Verification Source: https://context7.com/asdf-community/asdf-golang/llms.txt Demonstrates downloading Go archives and verifying their SHA-256 checksums. Checksum verification can be skipped using an environment variable. ```bash # Normal download with checksum verification (handled automatically by asdf install) asdf install golang 1.22.3 # Platform 'linux' supported! # verifying checksum # /home/user/.asdf/downloads/golang/1.22.3/archive.tar.gz: OK # checksum verified # Skip checksum (e.g., for air-gapped environments or known upstream issues) ASDF_GOLANG_SKIP_CHECKSUM=1 asdf install golang 1.22.3 # Platform 'linux' supported! # checksum skipped # Override architecture (e.g., force amd64 on ARM host) ASDF_GOLANG_OVERWRITE_ARCH=amd64 asdf install golang 1.15.8 # Platform 'darwin' supported! # checksum verified ``` -------------------------------- ### Configure Go Environment Variables for Shells Source: https://context7.com/asdf-community/asdf-golang/llms.txt Provides scripts to set Go environment variables (GOROOT, GOPATH, GOBIN) for different shells (Bash, Zsh, Fish, Nushell). These scripts ensure tools outside of asdf shims also use the correct Go paths. ```bash # --- Bash (~/.bashrc) --- . ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.bash # --- Zsh (~/.zshrc) --- . ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.zsh # --- Fish (~/.config/fish/config.fish) --- source (echo $ASDF_DATA_DIR | if test -z $it; echo $HOME/.asdf; else echo $it; end)/plugins/golang/set-env.fish # --- Nushell (env.nu) --- source (if ($env.ASDF_DATA_DIR | empty?) { echo $nu.env.HOME/.asdf } { echo $env.ASDF_DATA_DIR })/plugins/golang/set-env.nu # After sourcing, verify variables are set correctly: echo $GOROOT # e.g. /home/user/.asdf/installs/golang/1.22.3/go echo $GOPATH # e.g. /home/user/.asdf/installs/golang/1.22.3/packages echo $GOBIN # e.g. /home/user/.asdf/installs/golang/1.22.3/bin ``` -------------------------------- ### Enable Legacy Version File Parsing Source: https://context7.com/asdf-community/asdf-golang/llms.txt Configures the plugin to resolve Go versions from `.go-version`, `go.mod`, and `go.work` files. Set `ASDF_GOLANG_MOD_VERSION_ENABLED` to `true` to enable, or `false` to disable. ```bash # Enable go.mod and go.work version resolution (recommended explicit setting) export ASDF_GOLANG_MOD_VERSION_ENABLED=true # Disable go.mod/go.work resolution (use only .go-version / .tool-versions) export ASDF_GOLANG_MOD_VERSION_ENABLED=false # Example go.mod — the plugin will select the highest installed 1.x.y cat go.mod # module github.com/example/myapp # go 1.21 # With 1.21.0, 1.21.5, and 1.21.11 installed, asdf will activate 1.21.11 go version # go version go1.21.11 linux/amd64 # Example .go-version — exact version is used echo "1.22.3" > .go-version go version # go version go1.22.3 linux/amd64 ``` -------------------------------- ### Source Go Environment Variables for Nushell Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Source the set-env script in your env.nu file to ensure Go environment variables are correctly set for Nushell. ```nu source (if ($env.ASDF_DATA_DIR | empty?) { echo $nu.env.HOME/.asdf } { echo $env.ASDF_DATA_DIR })/plugins/golang/set-env.nu ``` -------------------------------- ### Source Go Environment Variables for Zsh Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Source the set-env script in your .zshrc file to ensure Go environment variables are correctly set for Zsh. ```bash . ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.zsh ``` -------------------------------- ### Source Go Environment Variables for Bash Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Source the set-env script in your .bashrc file to ensure Go environment variables are correctly set for Bash. ```bash . ${ASDF_DATA_DIR:-$HOME/.asdf}/plugins/golang/set-env.bash ``` -------------------------------- ### Source Go Environment Variables for Fish Source: https://github.com/asdf-community/asdf-golang/blob/master/README.md Source the set-env script in your config.fish file to ensure Go environment variables are correctly set for Fish shell. ```fish source (echo $ASDF_DATA_DIR | if test -z $it; echo $HOME/.asdf; else echo $it; end)/plugins/golang/set-env.fish ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.