DEV Community

Yusuke Hasegawa
Yusuke Hasegawa

Posted on • Originally published at Medium on

ターミナルがダサいとモテない。gvmとgupでgoのversion upとgo関連をまとめてupgradeする。

go installはgupで管理できます。


Photo by David Thielen on Unsplash

macOSで日頃、お仕事をしているわけですが

goで管理されているToolをたくさん使っています。

brewでgoを管理すると、何かで問題があったときに混乱するので支配したい!なんて言う人はgupが便利です。

GitHub - nao1215/gup: gup - Update binaries installed by "go install" with goroutines.

gup — Update binaries installed by “go install”

なんて書いてある通りでgo installしたもののupdate管理を助けてくれます。

Install gup

まずはgupのInstall

GitHub - nao1215/gup: gup - Update binaries installed by "go install" with goroutines.

How to installに書いてあります。

go install github.com/nao1215/gup@latest
Enter fullscreen mode Exit fullscreen mode

gup export

使い方は簡単です。

gup export
Enter fullscreen mode Exit fullscreen mode

とするだけで、 .config/gup/gup.conf にファイルが出力されます。

いろいろ入れたりして遊んでいるので汚れていますが、自分のをここに

CodeWeaver = github.com/tesserato/CodeWeaver
cheat = github.com/cheat/cheat/cmd/cheat
chezmoi = github.com/twpayne/chezmoi
curlie = github.com/rs/curlie
d2 = oss.terrastruct.com/d2
dasel = github.com/tomwright/dasel/v2/cmd/dasel
dbee = github.com/kndndrj/nvim-dbee/dbee
direnv = github.com/direnv/direnv
dive = github.com/wagoodman/dive
doggo = github.com/mr-karan/doggo/cmd/doggo
duf = github.com/muesli/duf
flog = github.com/mingrammer/flog
fx = github.com/antonmedv/fx
gama = github.com/termkit/gama
gdu = github.com/dundee/gdu
ghq = github.com/x-motemen/ghq
glance = github.com/glanceapp/glance
glow = github.com/charmbracelet/glow
go-global-update = github.com/Gelio/go-global-update
goreleaser = github.com/goreleaser/goreleaser
gostatus = github.com/shurcooL/gostatus
gum = github.com/charmbracelet/gum
gup = github.com/nao1215/gup
hugo = github.com/gohugoio/hugo
lazydocker = github.com/jesseduffield/lazydocker
lazygit = github.com/jesseduffield/lazygit
lazysql = github.com/jorgerojas26/lazysql
lenv = github.com/mah0x211/lenv
pdtm = github.com/projectdiscovery/pdtm/cmd/pdtm
peco = github.com/peco/peco/cmd/peco
runn = github.com/k1LoW/runn/cmd/runn
shfmt = mvdan.cc/sh/v3/cmd/shfmt
skate = github.com/charmbracelet/skate
superfile = github.com/yorukot/superfile
telegraf = github.com/influxdata/telegraf/cmd/telegraf
trivy = github.com/aquasecurity/trivy/cmd/trivy
usql = github.com/xo/usql
viking = github.com/d3witt/viking
xo = github.com/xo/xo
xq = github.com/sibprogrammer/xq
yj = github.com/sclevine/yj
Enter fullscreen mode Exit fullscreen mode

gup check

gup check を実行すると、 gup export で出力された .config/gup/gup.conf にある各go installされたものを確認し差分があればupdateをすることができます。

> gup check
check binary under $GOPATH/bin or $GOBIN
[1/40] github.com/tesserato/CodeWeaver (Already up-to-date: v0.0.14 / go1.24.3)
[2/40] github.com/charmbracelet/glow (Already up-to-date: v1.5.1 / go1.24.3)
[3/40] github.com/termkit/gama (Already up-to-date: v1.2.1 / go1.24.3)
[4/40] github.com/muesli/duf (Already up-to-date: v0.8.1 / go1.24.3)
[5/40] github.com/rs/curlie (Already up-to-date: v1.8.2 / go1.24.3)
[6/40] github.com/kndndrj/nvim-dbee/dbee (Already up-to-date: v0.0.0-20250508081016-ece254aaa322 / go1.24.3)
[7/40] github.com/cheat/cheat/cmd/cheat (Already up-to-date: v0.0.0-20240108203448-7908a678dfb1 / go1.24.3)
[8/40] github.com/sclevine/yj (Already up-to-date: v0.0.0-20210612025309-737bdf40a5d1 / go1.24.3)
[9/40] github.com/twpayne/chezmoi (Already up-to-date: v1.8.11 / go1.24.3)
[10/40] github.com/x-motemen/ghq (Already up-to-date: v1.8.0 / go1.24.3)
[11/40] github.com/dundee/gdu (Already up-to-date: v1.7.1 / go1.24.3)
[12/40] github.com/mingrammer/flog (Already up-to-date: v0.4.4 / go1.24.3)
[13/40] github.com/glanceapp/glance (Already up-to-date: v0.7.13 / go1.24.3)
[14/40] github.com/peco/peco/cmd/peco (Already up-to-date: v0.5.11 / go1.24.3)
[15/40] github.com/jesseduffield/lazydocker (Already up-to-date: v0.24.1 / go1.24.3)
[16/40] github.com/goreleaser/goreleaser (Already up-to-date: v1.26.2 / go1.24.3)
[17/40] github.com/charmbracelet/gum (Already up-to-date: v0.16.0 / go1.24.3)
[18/40] github.com/direnv/direnv (Already up-to-date: v2.20.1+incompatible / go1.24.3)
[19/40] github.com/shurcooL/gostatus (Already up-to-date: v0.0.0-20230709195902-7e7a12e3b18b / go1.24.3)
[20/40] github.com/wagoodman/dive (Already up-to-date: v0.13.1 / go1.24.3)
[21/40] oss.terrastruct.com/d2 (Already up-to-date: v0.7.0 / go1.24.3)
[22/40] github.com/jesseduffield/lazygit (Already up-to-date: v0.50.0 / go1.24.3)
[23/40] github.com/jorgerojas26/lazysql (Already up-to-date: v0.3.7 / go1.24.3)
[24/40] github.com/nao1215/gup (Already up-to-date: v0.27.8 / go1.24.3)
[25/40] github.com/mah0x211/lenv (Already up-to-date: v0.9.1 / go1.24.3)
[26/40] github.com/k1LoW/runn/cmd/runn (Already up-to-date: v0.130.2 / go1.24.3)
[27/40] github.com/yorukot/superfile (Already up-to-date: v1.2.1 / go1.24.3)
[28/40] github.com/projectdiscovery/pdtm/cmd/pdtm (Already up-to-date: v0.1.1 / go1.24.3)
[29/40] github.com/influxdata/telegraf/cmd/telegraf (Already up-to-date: v1.34.3 / go1.24.3)
[30/40] mvdan.cc/sh/v3/cmd/shfmt (Already up-to-date: v3.11.0 / go1.24.3)
[31/40] github.com/charmbracelet/skate (Already up-to-date: v1.0.1 / go1.24.3)
[32/40] github.com/mr-karan/doggo/cmd/doggo (Already up-to-date: v1.0.5 / go1.24.3)
[33/40] github.com/d3witt/viking (Already up-to-date: v0.2.1 / go1.24.3)
[34/40] github.com/aquasecurity/trivy/cmd/trivy (Already up-to-date: v0.62.1 / go1.24.3)
[35/40] github.com/xo/usql (Already up-to-date: v0.19.23 / go1.24.3)
[36/40] github.com/gohugoio/hugo (Already up-to-date: v0.147.3 / go1.24.3)
[37/40] github.com/antonmedv/fx (Already up-to-date: v0.0.0-20250512231259-6b77303f3268 / go1.24.3)
[38/40] github.com/xo/xo (Already up-to-date: v1.0.2 / go1.24.3)
[39/40] github.com/sibprogrammer/xq (Already up-to-date: v1.3.0 / go1.24.3)
[40/40] github.com/tomwright/dasel/v2/cmd/dasel (Already up-to-date: v2.8.1 / go1.24.3)
Enter fullscreen mode Exit fullscreen mode

とっても簡単です。

Appendix: gvmの管理の便利Functions

gvm-go-upgrade()

私は、めんどくさいのでgvmで管理されているgo versionをupgradeしたいとき用にbashのfunctionを書いています。

  function gvm-go-upgrade() {
    declare go_version=$(gvm listall | sed -e "s/ *//g" | grep -v -e release -e rc -e beta -e "^$" | tail -1)
    echo "go version: ${go_version}"
    declare go_exists=$(gvm list | grep ${go_version})
    if ["${go_exists}" == ${go_version}]; then
      echo "${go_version} exists."
    else
      gvm install ${go_version} --with-protobuf --with-build-tools --binary
      gvm use ${go_version} --default
      go install github.com/nao1215/gup@latest
      gvm-go-install
    fi
  }
Enter fullscreen mode Exit fullscreen mode

gvm-go-upgrade を実行すればgvmでInstallできるgo versionに自分のより新しい物があれば、それを指定してInstallします。

ちょっとsedやらgrepやらを駆使しているので使えなくなるときがあるかもしれないです😅

gvm-du()

goはcacheやらmodcacheやらtestcacheやらでかなりdiskを食うので、確認のためにこれもFunction化しています。

  function gvm-du() {
    du $(go env GOPATH GOCACHE)
  }
Enter fullscreen mode Exit fullscreen mode

実行してみると

出力が普通のduと異なりますが、goのdufを利用しています。

GitHub - muesli/duf: Disk Usage/Free Utility - a better 'df' alternative

gvm-clean()

上記の通り、diskを食うのとgo installに失敗した際などにめんどくさいのでこれもFunction化しています。

  function gvm-clean() {
    go clean -cache -modcache -testcache
  }
Enter fullscreen mode Exit fullscreen mode

実行すると各種cacheを削除してくれます。

gvm-cleanした後に、gvm-cleanを実行するとこのようになります。

20GB超えが1.4Gまで減ります。

ただあんまりやると、各種ライブラリなどに都度拾いに行くようになるのでご利用は計画的に🧛

以前はgoenv(このmedium書いてて見つけた別のgo-nv/goenv)やgobrewを使ってましたがgvmもそれなりに癖があるのでこちらも適度に触って慣れてから常用した方が良いです。

ただいずれにせよ gup export.config/gup/gup.conf が存在すればいつでもgo versionが変わっても、自分のTool環境に戻せるのでgupは使うと捗ります。

github starが多いからこっちの方がいいかもなぁ

余裕ある時触ってみよう

GitHub - go-nv/goenv: 🚙 Like pyenv and rbenv, but for Go.

Top comments (0)