Skip to content

Instantly share code, notes, and snippets.

@tbxark
Created November 22, 2024 04:16
Show Gist options
  • Select an option

  • Save tbxark/2346221d5534e03ea341f0d854d51f71 to your computer and use it in GitHub Desktop.

Select an option

Save tbxark/2346221d5534e03ea341f0d854d51f71 to your computer and use it in GitHub Desktop.
Update go bin to the latest version
#!/bin/bash
if [[ -z "$GOPATH" ]]; then
export GOPATH=~/go
fi
for bin in $GOPATH/bin/*; do
if [[ -x "$bin" ]]; then
path=$(go version -m "$bin" | grep "^[[:space:]]*path" | awk '{print $2}')
if [[ "$path" == */* ]]; then
echo "Updating $bin from $path"
go install "$path@latest"
else
echo "$bin is not installed from a remote path."
fi
else
echo "$bin is not executable."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment