3

When I install a Go software with the suggested command, e.g.:

$ go install github.com/walles/moar@latest

it gets installed into $HOME/go/bin and I'm pretty happy with that, much faster than waiting for operating system repositories to get updated.

I'm looking for a way to list all the installed executables and their installed version and can't find it, even though I'm pretty sure the information is saved somewhere because the go install x@latest only does something if a new version is available, and quietly terminates doing nothing when latest version is already installed.

lapo
  • 423

2 Answers2

1

A while ago, they introduce a new flag to the go version subcommand.

calling

go version -m /path/to/your/binary

will display a list of module dependency, with the first one being this binary module itself, with its version.

$ go version -m ~/go/bin/moar 
/home/dolanor/go/bin/moar: go1.21.0
    path    github.com/walles/moar
    mod github.com/walles/moar  v1.26.0 h1:6dvuCGd+iSH1HVJ7I/23DaGw+mmXDt6S6IF4MvqFGrs=
    dep github.com/alecthomas/chroma/v2 v2.12.0 h1:Wh8qLEgMMsN7mgyG8/qIpegky2Hvzr4By6gEF7cmWgw=
    dep github.com/dlclark/regexp2  v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
    dep github.com/klauspost/compress   v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
    dep github.com/sirupsen/logrus  v1.8.1  h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
    dep github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
    dep golang.org/x/exp    v0.0.0-20240103183307-be819d1f06fc  h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
    dep golang.org/x/sys    v0.1.0  h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
    dep golang.org/x/term   v0.0.0-20210503060354-a79de5458b56  h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
    build   -buildmode=exe
    build   -compiler=gc
    build   DefaultGODEBUG=panicnil=1
    build   CGO_ENABLED=1
    build   CGO_CFLAGS=
    build   CGO_CPPFLAGS=
    build   CGO_CXXFLAGS=
    build   CGO_LDFLAGS=
    build   GOARCH=amd64
    build   GOOS=linux
    build   GOAMD64=v1

We can see it's at version v1.26.0

mod github.com/walles/moar  v1.26.0 h1:6dvuCGd+iSH1HVJ7I/23DaGw+mmXDt6S6IF4MvqFGrs=
Dolanor
  • 419
0
#!/bin/bash
BIN_DIR="$HOME/go/bin"

for binary in "$BIN_DIR"/*; do
  if [[ -x "$binary" ]]; then
    echo -n "$(basename "$binary") version: "

    # Try different version flags
    "$binary" --version 2>/dev/null ||
    "$binary" -version 2>/dev/null ||
    "$binary" version 2>/dev/null ||
    echo "Version command not found"
  fi
done

This should list all the installed binaries as they are usually stored in the go/bin folder in Home directory. Some binaries may fail to print the versions as all of their version flag is not same.