{"id":10008206,"date":"2023-08-31T17:59:15","date_gmt":"2023-08-31T09:59:15","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008206"},"modified":"2023-08-31T17:59:15","modified_gmt":"2023-08-31T09:59:15","slug":"golang-%e4%bd%bf%e7%94%a8gvm%e8%bf%9b%e8%a1%8c%e7%89%88%e6%9c%ac%e6%8e%a7%e5%88%b6","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008206","title":{"rendered":"Golang-\u4f7f\u7528gvm\u8fdb\u884c\u7248\u672c\u63a7\u5236"},"content":{"rendered":"<p>\u5f53\u4f60\u60f3\u4e3a\u6bcf\u4e2a\u9879\u76ee\u5207\u6362 go \u7248\u672c\u65f6\uff0cgvm (Go Version Manager) \u5f88\u65b9\u4fbf\u3002<\/p>\n<p>\u8fd9\u91cc\uff0c\u6211\u5c06\u4ecb\u7ecd\u201c\u5982\u4f55\u5728Mac\u4e0a\u5b89\u88c5gvm\u201d\u548c\u201c\u5982\u4f55\u4f7f\u7528gvm\u201d<\/p>\n<h2>\u4f7f\u7528\u51c6\u5907<\/h2>\n<h3>\u4ec5\u9002\u7528\u4e8e Mac \u7684\u51c6\u5907\u5de5\u4f5c<\/h3>\n<p>\u6309\u7167MacOSX \u8981\u6c42\u4e2d\u7684\u8bf4\u660e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre><code class=\"shell\">xcode-select --install\nbrew update\nbrew install mercurial<\/code><\/pre>\n<h3>gvm\u5b89\u88c5<\/h3>\n<p>\u6211\u4f7f\u7528 zsh \u4f5c\u4e3a\u6211\u7684 shell\u3002<\/p>\n<pre><code class=\"shell\">$ echo $SHELL\n\/bin\/zsh<\/code><\/pre>\n<p>\u5bf9\u4e8e zsh\uff0c\u60a8\u53ef\u4ee5\u8fd9\u6837\u5b89\u88c5\uff1a<\/p>\n<pre><code class=\"shell\">$ zsh &lt; &lt;(curl -s -S -L https:\/\/raw.githubusercontent.com\/moovweb\/gvm\/master\/binscripts\/gvm-installer)\nCloning from https:\/\/github.com\/moovweb\/gvm.git to \/Users\/user_name\/.gvm\nNo existing Go versions detected\nInstalled GVM v1.0.22\n\nPlease restart your terminal session or to get started right away run\n `source \/Users\/user_name\/.gvm\/scripts\/gvm`<\/code><\/pre>\n<p><code>~\/.zshrc<\/code> \u4ee5\u4e0b\u884c\u88ab\u6dfb\u52a0\u5230\u6700\u540e\u4e00\u884c<\/p>\n<pre><code class=\"shell\">[[ -s &quot;\/Users\/user_name\/.gvm\/scripts\/gvm&quot; ]] &amp;&amp; source &quot;\/Users\/user_name\/.gvm\/scripts\/gvm&quot;<\/code><\/pre>\n<p>\u91cd\u65b0\u542f\u52a8\u7ec8\u7aef gvm \u5373\u53ef\u4f7f\u7528<\/p>\n<pre><code class=\"shell\">$ gvm help\nUsage: gvm [command]\n\nDescription:\n  GVM is the Go Version Manager\n\nCommands:\n  version    - print the gvm version number\n  get        - gets the latest code (for debugging)\n  use        - select a go version to use (--default to set permanently)\n  diff       - view changes to Go root\n  help       - display this usage text\n  implode    - completely remove gvm\n  install    - install go versions\n  uninstall  - uninstall go versions\n  cross      - install go cross compilers\n  linkthis   - link this directory into GOPATH\n  list       - list installed go versions\n  listall    - list available versions\n  alias      - manage go version aliases\n  pkgset     - manage go packages sets\n  pkgenv     - edit the environment for a package set<\/code><\/pre>\n<h2>\u5982\u4f55\u4f7f\u7528gvm<\/h2>\n<h3>\u67e5\u770b\u53ef\u4ee5\u5b89\u88c5\u7684\u7248\u672c<\/h3>\n<p><code>gvm listall<\/code> \u60a8\u53ef\u4ee5\u68c0\u67e5\u53ef\u4ee5\u5b89\u88c5\u54ea\u4e2a\u7248\u672c<\/p>\n<pre><code class=\"shell\">$ gvm listall\n\ngvm gos (available)\n\n   go1\n   go1.0.1\n   go1.0.2\n   go1.0.3\n   go1.1\n   go1.1rc2\n   go1.1rc3\n   :<\/code><\/pre>\n<h3>\u5b89\u88c5 go \u7248\u672c<\/h3>\n<p>M1 Mac \u6211\u6b63\u5728\u4f7f\u7528\uff0c\u4f46\u662f\u5f53\u6211\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u65f6\uff0c\u51fa\u73b0\u9519\u8bef<\/p>\n<pre><code class=\"shell\">$ gvm install go1.16.15 -B\nInstalling go1.16.15 from binary source\nERROR: Binary Go unavailable for this platform\n$ \n$ gvm install go1.17.5 -B \nInstalling go1.17.5 from binary source\nERROR: Binary Go unavailable for this platform<\/code><\/pre>\n<p>\u6211\u5728\u4ee5\u4e0b\u65b9\u9762\u53d6\u5f97\u4e86\u6210\u529f\uff1a<\/p>\n<pre><code class=\"shell\">$ brew install go\n==&gt; Downloading https:\/\/ghcr.io\/v2\/homebrew\/core\/go\/manifests\/1.18\n######################################################################## 100.0%\n    :\n$ \n$ gvm install go1.16.15   \nInstalling go1.16.15...\n * Compiling...\ngo1.16.15 successfully installed!\n$ \n$ gvm use go1.16.15 --default\nNow using version go1.16.15\n$ \n$ go version          \ngo version go1.16.15 darwin\/arm64<\/code><\/pre>\n<p>\u4e4b\u540e\uff0c\u5373\u4f7f\u6211\u5378\u8f7d\u4e86\u7528brew\u5b89\u88c5\u7684go\uff0c\u6211\u4e5f\u80fd\u591f\u5b89\u88c5\u53e6\u4e00\u4e2a\u7248\u672c\u7684go\u3002<\/p>\n<pre><code class=\"shell\">$ brew uninstall go          \nUninstalling \/opt\/homebrew\/Cellar\/go\/1.18... (11,947 files, 595.3MB)\n$ \n$ gvm install go1.17.5   \nInstalling go1.17.5...\n * Compiling...\ngo1.17.5 successfully installed!<\/code><\/pre>\n<p>1.16.15 \u5df2\u5b89\u88c5 1.17.5 \uff0c\u4f46\u4e3a\u6bcf\u4e2a\u7248\u672c\u751f\u6210\u4e86\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre><code class=\"shell\">$ ls ~\/.gvm\/gos \ngo1.16.15       go1.17.5<\/code><\/pre>\n<h3>\u5207\u6362go\u7248\u672c\u6765\u4f7f\u7528<\/h3>\n<p>\u6211\u76ee\u524d\u6b63\u5728go1.16.15 \u4f7f\u7528<\/p>\n<pre><code class=\"shell\">$ gvm list\n\ngvm gos (installed)\n\n=&gt; go1.16.15\n   go1.17.5\n$ \n$ echo $GOPATH\n\/Users\/user_name\/.gvm\/pkgsets\/go1.16.15\/global\n$ \n$ echo $GOROOT\n\/Users\/user_name\/.gvm\/gos\/go1.16.15\n$ \n$ go version\ngo version go1.16.15 darwin\/arm64\n$\n$ which go\n\/Users\/user_name\/.gvm\/gos\/go1.16.15\/bin\/go<\/code><\/pre>\n<p><code>1.17.5<\/code> \u6211\u4f1a\u5c1d\u8bd5\u5207\u6362\u5230<\/p>\n<pre><code class=\"shell\">$ gvm use go1.17.5 --default \nNow using version go1.17.5\n$ \n$ gvm list                  \n\ngvm gos (installed)\n\n   go1.16.15\n=&gt; go1.17.5\n\n$ \n$ echo $GOPATH\n\/Users\/user_name\/.gvm\/pkgsets\/go1.17.5\/global\n$ \n$ echo $GOROOT\n\/Users\/user_name\/.gvm\/gos\/go1.17.5\n$ \n$ go version\ngo version go1.17.5 darwin\/arm64\n$ \n$ which go\n\/Users\/user_name\/.gvm\/gos\/go1.17.5\/bin\/go<\/code><\/pre>\n<h2>\u53c2\u8003<\/h2>\n<p><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=4Pf8GIZXcVTFzk4zWpf7jg%3D%3D.qdh8GzesB1EW5llzSGrhhHK95qPRSonVmtuXqptn6VI%3D\" rel=\"noopener noreferrer\">https:\/\/github.com\/moovweb\/gvm<\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044168899\">https:\/\/segmentfault.com\/a\/1190000044168899<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u4f60\u60f3\u4e3a\u6bcf\u4e2a\u9879\u76ee\u5207\u6362 go \u7248\u672c\u65f6\uff0cgvm (Go Version Manager) \u5f88\u65b9\u4fbf\u3002 \u8fd9\u91cc\uff0c\u6211\u5c06\u4ecb\u7ecd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008206","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008206"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008206\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}