欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

go语言-在mac下brew升级golang

程序员文章站 2022-06-16 11:35:11
在命令行下直接运行:brew upgrade go补充:mac下更新delve调试go语言概述delve 是golang调试程序。但如果版本不配套, mac下goland 调试,step over会不...

在命令行下直接运行:

brew upgrade go

补充:mac下更新delve调试go语言

概述

delve 是golang调试程序。但如果版本不配套, mac下goland 调试,step over会不起作用,直接变成执行完毕或者到下一个断点。 需要更新调试器delve解决。

go get安装

mac下安装delve,官方教程是两步。

$ xcode-select --install
xcode-select: error: command line tools are already installed, use "software update" to install updates
$ go get -u github.com/derekparker/delve/cmd/dlv

但go get 一直不返回。

homebrew 安装

zhouhh@/users/zhouhh $ brew install go-delve/delve/delve
updating homebrew...
==> installing delve from go-delve/delve
==> downloading https://github.com/derekparker/delve/archive/v1.0.0.tar.gz
already downloaded: /users/zhouhh/library/caches/homebrew/delve-1.0.0.tar.gz
security: seckeychainsearchcopynext: the specified item could not be found in the keychain.
==> generating dlv-cert
==> openssl req -new -newkey rsa:2048 -x509 -days 3650 -nodes -config dlv-cert.cfg -extensions codesign_reqext -batch -out dlv-cert.cer -keyout dlv-cert.key
==> [sudo] installing dlv-cert as root
==> sudo security add-trusted-cert -d -r trustroot -k /library/keychains/system.keychain dlv-cert.cer
last 15 lines from /users/zhouhh/library/logs/homebrew/delve/02.sudo:
2018-08-09 17:07:38 +0800
sudo
security
add-trusted-cert
-d
-r
trustroot
-k
/library/keychains/system.keychain
dlv-cert.cer
if reporting this issue please do so at (not homebrew/brew or homebrew/core):
https://github.com/go-delve/homebrew-delve/issues
these open issues may also help:
upgrade to delve fails https://github.com/go-delve/homebrew-delve/issues/20
/usr/local/homebrew/library/homebrew/exceptions.rb:426:in `block in dump': undefined method `check_for_bad_install_name_tool' for #<homebrew::diagnostic::checks:0x007fc5df858bd8> (nomethoderror)
did you mean?  check_for_tap_ruby_files_locations
 from /usr/local/homebrew/library/homebrew/exceptions.rb:425:in `each'
 from /usr/local/homebrew/library/homebrew/exceptions.rb:425:in `dump'
 from /usr/local/homebrew/library/homebrew/brew.rb:138:in `rescue in <main>'
 from /usr/local/homebrew/library/homebrew/brew.rb:30:in `<main>'

这是因为证书有问题。 可以到homebrew缓存下载的delve里处理一下。

zhouhh@/users/zhouhh $ cd $home/library/caches/homebrew
zhouhh@/users/zhouhh/library/caches/homebrew $ ls del*
delve-1.0.0.tar.gz
zhouhh@/users/zhouhh/library/caches/homebrew $ tar zxvf delve-1.0.0.tar.gz
zhouhh@/users/zhouhh/library/caches/homebrew $ sh delve-1.0.0/scripts/gencert.sh
password:

再安装成功

zhouhh@/users/zhouhh/library/caches/homebrew $ cgo_enabled=1 brew install go-delve/delve/delve
==> installing delve from go-delve/delve
==> downloading https://github.com/derekparker/delve/archive/v1.0.0.tar.gz
already downloaded: /users/zhouhh/library/caches/homebrew/delve-1.0.0.tar.gz
==> dlv-cert is already installed, no need to create it
==> make build build_sha=v1.0.0
==> caveats
if you get "could not launch process: could not fork/exec", you need to try
in a new terminal.
when uninstalling, to remove the dlv-cert certificate, run this command:
    $ sudo security delete-certificate -t -c dlv-cert /library/keychains/system.keychain
alternatively, you may want to delete from the keychain (with the imported private key).
==> summary
????  /usr/local/cellar/delve/1.0.0: 6 files, 10.6mb, built in 13 seconds

安装成功

修改ide环境

安装完最新的 delve 后,如 brew install delve, 然后在intellij或goland中点击

help → edit custom properties...

添加新行

dlv.path=/usr/local/bin/dlv

保存重启,解决step over(f8) 直接运行完毕的bug。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。