{"id":6396,"date":"2022-01-22T21:22:12","date_gmt":"2022-01-22T13:22:12","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=6396"},"modified":"2025-07-29T15:10:39","modified_gmt":"2025-07-29T07:10:39","slug":"go-10","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2022\/01\/22\/go-10\/","title":{"rendered":"\u5b89\u88c5golang"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u4e00\u3001\u4e0b\u8f7d\u5730\u5740\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Go\u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/golang.org\/dl\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e8c\u3001windows\u5e73\u53f0\u5b89\u88c5\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u76f4\u63a5\u4e0b\u4e00\u6b65\u5b89\u88c5\u5373\u53ef\uff0c\u53ef\u81ea\u5b9a\u4e49\u4fee\u6539\u5b89\u88c5\u8def\u5f84\uff0c\u5b89\u88c5\u540e\u53ef\u5728\u547d\u4ee4\u884c\u67e5\u770b\u7ed3\u679c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"713\" height=\"131\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-2.png\" alt=\"\" class=\"wp-image-6398\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-2.png 713w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-2-300x55.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-2-600x110.png 600w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u914d\u7f6eGOPATH\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GOPATH \u662f\u4e00\u4e2a\u73af\u5883\u53d8\u91cf\uff0c\u7528\u6765\u8868\u660e\u4f60\u5199\u7684 go \u9879\u76ee\u7684\u5b58\u653e\u8def\u5f84<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GOPATH \u8def\u5f84\u6700\u597d\u53ea\u8bbe\u7f6e\u4e00\u4e2a\uff0c\u6240\u6709\u7684\u9879\u76ee\u4ee3\u7801\u90fd\u653e\u5230 GOPATH \u7684 src \u76ee\u5f55\u4e0b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u4f8b\u5b50\u4e2d\uff0c\u5728D\u76d8\u4e0b\u521b\u5efa\u76ee\u5f55Goproject\u4f5c\u4e3aGOPATH\u8def\u5f84\uff0c\u5e76\u914d\u7f6e\u73af\u5883\u53d8\u91cf(\u5982\u679c\u4e0d\u5b58\u5728)\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"231\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/2-3.png\" alt=\"\" class=\"wp-image-6399\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/2-3.png 706w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/2-3-300x98.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/2-3-600x196.png 600w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u540c\u65f6\u5c06go\u7684\u5b89\u88c5\u8def\u5f84\u548cGOPATH\u914d\u7f6e\u5230path\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"713\" height=\"220\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/3-3.png\" alt=\"\" class=\"wp-image-6400\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/3-3.png 713w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/3-3-300x93.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/3-3-600x185.png 600w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5728GOPATH\u8def\u5f84\u4e0b\u65b0\u5efa\u4e09\u4e2a\u6587\u4ef6\u5939\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>bin\uff1a\u7528\u4e8e\u5b58\u653e\u7f16\u8bd1\u540e\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6<\/li>\n\n\n\n<li>pkg\uff1a\u5b58\u653e\u7f16\u8bd1\u540e\u751f\u6210\u7684\u5f52\u6863\u6587\u4ef6<\/li>\n\n\n\n<li>src\uff1a\u5b58\u653e\u6e90\u4ee3\u7801\u6587\u4ef6<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fdb\u884c Go \u8bed\u8a00\u5f00\u53d1\u7684\u65f6\u5019\uff0c\u6211\u4eec\u7684\u4ee3\u7801\u603b\u662f\u4f1a\u4fdd\u5b58\u5728 $GOPATH\/src \u76ee\u5f55\u4e0b\u3002\u5728\u5de5\u7a0b\u7ecf\u8fc7 go build \u3001 go install \u6216 go get \u7b49\u6307\u4ee4\u540e\uff0c\u4f1a\u5c06\u4e0b\u8f7d\u7684\u7b2c\u4e09\u65b9\u5305\u6e90\u4ee3\u7801\u6587\u4ef6\u653e\u5728 $GOPATH\/src \u76ee\u5f55\u4e0b\uff0c \u4ea7\u751f\u7684\u4e8c\u8fdb\u5236\u53ef\u6267\u884c\u6587\u4ef6\u653e$GOPATH\/bin \u76ee\u5f55\u4e0b\uff0c\u751f\u6210\u7684\u4e2d\u95f4\u7f13\u5b58\u6587\u4ef6\u4f1a\u88ab\u4fdd\u5b58\u5728 $GOPATH\/pkg \u4e0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e09\u3001linux\u5b89\u88c5go<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\u5c06go\u5b89\u88c5\u5305\u4e0a\u4f20\u5230\u673a\u5668\u4e0a\uff0c\u89e3\u538b\uff0c\u5e76\u79fb\u52a8\u5230\/usr\/local\u76ee\u5f55\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001tar xf go1.18.1.linux-amd64.tar.gz\n2\u3001mv go \/usr\/local\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u7f16\u8f91\u73af\u5883\u53d8\u91cf\u6587\u4ef6\/etc\/profile\uff0c\u6dfb\u52a0\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export GOROOT=\/usr\/local\/go           \/\/GOROOT: go\u7684\u5b89\u88c5\u8def\u5f84\nexport PATH=$PATH:$GOROOT\/bin:\/data\/go\/bin\nexport GOPATH=\/data\/go                \/\/GOPATH: go\u7684\u5de5\u4f5c\u76ee\u5f55\nexport GOBIN=$GOPATH\/bin              \/\/GOBIN:GOPATH\u4e0b\u7684bin\u76ee\u5f55\uff0c\u53ef\u8bbe\u7f6e\u53ef\u4e0d\u8bbe\u7f6e<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"101\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/01\/18.png\" alt=\"\" class=\"wp-image-11205\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/01\/18.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/01\/18-300x43.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/01\/18-600x86.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u547d\u4ee4\u8ba9\u73af\u5883\u53d8\u91cf\u751f\u6548<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source \/etc\/profile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u5728GOPATH\u8def\u5f84\u4e0b\u521b\u5efa\u4e09\u4e2a\u6587\u4ef6\u5939\uff0c\u4e0ewindows\u90e8\u7f72\u65b9\u6cd5\u4e00\u6837\uff0c\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p \/data\/go\/{bin,pkg,src}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u6267\u884c\u547d\u4ee4\u67e5\u770b\u7248\u672c\u4e0e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go version\ngo env<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4ed6\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u7531\u4e8egoogle\u88ab\u963b\u62e6\uff0c\u6240\u4ee5\u8981\u8bbe\u7f6e\u4ee3\u7406\uff0c\u65b9\u4fbf\u62c9\u53d6\u9700\u8981\u7684\u5e93\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go env -w GOPROXY=https:\/\/goproxy.cn,direct \/\/\u56fd\u5185\u955c\u50cf\uff0c\u4e03\u725b\u4e91\u8fd0\u8425\ngo env -w GOPROXY=https:\/\/goproxy.io,direct \/\/\u5168\u7403\u670d\u52a1,\u652f\u6301\u79c1\u6709\u4ed3\u5e93\ngo env -w GOPROXY=https:\/\/proxy.golang.org,direct \/\/golang\u5b98\u65b9\u5e93\uff0c\u9700\u8981\u7ffb\u5899\ngo env -w GOPROXY=https:\/\/mirrors.aliyun.com\/goproxy,direct \/\/\u963f\u91cc\u4e91<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5982\u679c\u5728\u6ca1\u6709\u4f7f\u7528gomod\u7684\u60c5\u51b5\u4e0b\u8981\u62c9\u53d6\u54cd\u5e94\u7684\u5305\uff0c\u5e94\u8be5\u5148\u8bbe\u7f6eGO111MODULE=auto\uff0c\u7136\u540e\u5728\u6267\u884cgo get\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go env -w GO111MODULE=auto<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u7684GO111MODULE\u7528\u6cd5\u53ef\u53c2\u8003: <a href=\"https:\/\/blog.ywdevops.cn\/index.php\/2022\/05\/16\/go-mod\/\" target=\"_blank\" rel=\"noreferrer noopener\">gomod\u4f7f\u7528<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e0b\u8f7d\u5730\u5740\uff1a \u4e8c\u3001windows\u5e73\u53f0\u5b89\u88c5\uff1a 1\u3001\u76f4\u63a5\u4e0b\u4e00\u6b65\u5b89\u88c5\u5373\u53ef\uff0c\u53ef\u81ea\u5b9a\u4e49\u4fee\u6539\u5b89\u88c5\u8def\u5f84\uff0c\u5b89\u88c5\u540e\u53ef\u5728\u547d\u4ee4\u884c\u67e5 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":6404,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-6396","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go","category-rong"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/6396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=6396"}],"version-history":[{"count":20,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/6396\/revisions"}],"predecessor-version":[{"id":18751,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/6396\/revisions\/18751"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/6404"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}