{"id":57686,"date":"2024-10-10T20:20:16","date_gmt":"2024-10-10T12:20:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/57686\/"},"modified":"2024-10-10T20:20:16","modified_gmt":"2024-10-10T12:20:16","slug":"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80-gopath-%e8%a9%b3%e8%a7%a3%ef%bc%88go-%e8%aa%9e%e8%a8%80%e5%b7%a5%e4%bd%9c%e7%9b%ae%e9%8c%84%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/57686\/","title":{"rendered":"GO\u6559\u7a0b: Go \u8a9e\u8a00 GOPATH \u8a73\u89e3\uff08Go \u8a9e\u8a00\u5de5\u4f5c\u76ee\u9304\uff09"},"content":{"rendered":"<h1 id=\"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80-gopath-%e8%a9%b3%e8%a7%a3%ef%bc%88go-%e8%aa%9e%e8%a8%80%e5%b7%a5%e4%bd%9c%e7%9b%ae%e9%8c%84%ef%bc%89-GuRtKgwySE\">GO\u6559\u7a0b: Go \u8a9e\u8a00 GOPATH \u8a73\u89e3\uff08Go \u8a9e\u8a00\u5de5\u4f5c\u76ee\u9304\uff09<\/h1>\n<p>Go \u8a9e\u8a00\uff08\u53c8\u7a31 Golang\uff09\u662f\u4e00\u7a2e\u7531 Google \u958b\u767c\u7684\u958b\u6e90\u7de8\u7a0b\u8a9e\u8a00\uff0c\u4ee5\u5176\u7c21\u6f54\u6027\u548c\u9ad8\u6548\u6027\u800c\u805e\u540d\u3002\u5728\u5b78\u7fd2 Go \u8a9e\u8a00\u7684\u904e\u7a0b\u4e2d\uff0c\u7406\u89e3 GOPATH \u7684\u6982\u5ff5\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002GOPATH \u662f Go \u8a9e\u8a00\u7684\u5de5\u4f5c\u76ee\u9304\uff0c\u8ca0\u8cac\u7ba1\u7406 Go \u7684\u6e90\u4ee3\u78bc\u3001\u7de8\u8b6f\u548c\u5b89\u88dd\u904e\u7a0b\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e GOPATH \u7684\u7d50\u69cb\u3001\u914d\u7f6e\u53ca\u5176\u5728 Go \u958b\u767c\u4e2d\u7684\u91cd\u8981\u6027\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-gopath%ef%bc%9f-GuRtKgwySE\">\u4ec0\u9ebc\u662f GOPATH\uff1f<\/h2>\n<p>GOPATH \u662f\u4e00\u500b\u74b0\u5883\u8b8a\u91cf\uff0c\u7528\u65bc\u6307\u5b9a Go \u8a9e\u8a00\u7684\u5de5\u4f5c\u76ee\u9304\u3002\u5b83\u544a\u8a34 Go \u7de8\u8b6f\u5668\u548c\u5de5\u5177\u5728\u54ea\u88e1\u67e5\u627e Go \u6e90\u4ee3\u78bc\u548c\u4f9d\u8cf4\u9805\u3002GOPATH \u7684\u9ed8\u8a8d\u503c\u901a\u5e38\u662f\u7528\u6236\u4e3b\u76ee\u9304\u4e0b\u7684 <code>go<\/code> \u76ee\u9304\uff0c\u4f46\u7528\u6236\u53ef\u4ee5\u6839\u64da\u9700\u8981\u9032\u884c\u81ea\u5b9a\u7fa9\u3002<\/p>\n<h2 id=\"gopath-%e7%9a%84%e7%b5%90%e6%a7%8b-GuRtKgwySE\">GOPATH \u7684\u7d50\u69cb<\/h2>\n<p>GOPATH \u76ee\u9304\u901a\u5e38\u5305\u542b\u4e09\u500b\u4e3b\u8981\u5b50\u76ee\u9304\uff1a<\/p>\n<ul>\n<li><code>src<\/code>\uff1a\u5b58\u653e Go \u6e90\u4ee3\u78bc\u7684\u76ee\u9304\u3002\u6bcf\u500b Go \u5305\u90fd\u61c9\u8a72\u5728\u9019\u500b\u76ee\u9304\u4e0b\u6709\u81ea\u5df1\u7684\u5b50\u76ee\u9304\uff0c\u4e26\u4e14\u5b50\u76ee\u9304\u7684\u7d50\u69cb\u61c9\u8a72\u8207\u5176\u5c0e\u5165\u8def\u5f91\u76f8\u5c0d\u61c9\u3002<\/li>\n<li><code>pkg<\/code>\uff1a\u5b58\u653e\u7de8\u8b6f\u5f8c\u7684\u5305\u6587\u4ef6\uff0c\u9019\u4e9b\u6587\u4ef6\u662f\u4ee5\u64cd\u4f5c\u7cfb\u7d71\u548c\u67b6\u69cb\u70ba\u57fa\u790e\u7684\u3002<\/li>\n<li><code>bin<\/code>\uff1a\u5b58\u653e\u7de8\u8b6f\u5f8c\u7684\u53ef\u57f7\u884c\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u5047\u8a2d\u4f60\u7684 GOPATH \u8a2d\u7f6e\u70ba <code>\/home\/user\/go<\/code>\uff0c\u90a3\u9ebc\u4f60\u7684\u76ee\u9304\u7d50\u69cb\u53ef\u80fd\u5982\u4e0b\uff1a<\/p>\n<pre>\n\/home\/user\/go\n\u251c\u2500\u2500 bin\n\u251c\u2500\u2500 pkg\n\u2514\u2500\u2500 src\n    \u2514\u2500\u2500 example.com\n        \u2514\u2500\u2500 mypackage\n            \u251c\u2500\u2500 myfile.go\n            \u2514\u2500\u2500 myfile_test.go\n<\/pre>\n<h2 id=\"%e5%a6%82%e4%bd%95%e8%a8%ad%e7%bd%ae-gopath-GuRtKgwySE\">\u5982\u4f55\u8a2d\u7f6e GOPATH<\/h2>\n<p>\u8a2d\u7f6e GOPATH \u975e\u5e38\u7c21\u55ae\u3002\u4f60\u53ef\u4ee5\u5728\u4f60\u7684\u64cd\u4f5c\u7cfb\u7d71\u4e2d\u8a2d\u7f6e\u74b0\u5883\u8b8a\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u64cd\u4f5c\u7cfb\u7d71\u7684\u8a2d\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<h3 id=\"%e5%9c%a8-linux-%e6%88%96-macos-%e4%b8%ad-GuRtKgwySE\">\u5728 Linux \u6216 macOS \u4e2d<\/h3>\n<p>\u4f60\u53ef\u4ee5\u5728 <code>~\/.bash_profile<\/code> \u6216 <code>~\/.bashrc<\/code> \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>\nexport GOPATH=$HOME\/go\nexport PATH=$PATH:$GOPATH\/bin\n<\/pre>\n<p>\u7136\u5f8c\u904b\u884c <code>source ~\/.bash_profile<\/code> \u6216 <code>source ~\/.bashrc<\/code> \u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/p>\n<h3 id=\"%e5%9c%a8-windows-%e4%b8%ad-GuRtKgwySE\">\u5728 Windows \u4e2d<\/h3>\n<p>\u4f60\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u6b65\u9a5f\u8a2d\u7f6e GOPATH\uff1a<\/p>\n<ol>\n<li>\u53f3\u9375\u55ae\u64ca\u300c\u6b64\u96fb\u8166\u300d\uff0c\u9078\u64c7\u300c\u5c6c\u6027\u300d\u3002<\/li>\n<li>\u9ede\u64ca\u300c\u9ad8\u7d1a\u7cfb\u7d71\u8a2d\u7f6e\u300d\u3002<\/li>\n<li>\u5728\u300c\u7cfb\u7d71\u5c6c\u6027\u300d\u7a97\u53e3\u4e2d\uff0c\u9ede\u64ca\u300c\u74b0\u5883\u8b8a\u91cf\u300d\u3002<\/li>\n<li>\u5728\u300c\u7cfb\u7d71\u8b8a\u91cf\u300d\u90e8\u5206\uff0c\u9ede\u64ca\u300c\u65b0\u5efa\u300d\uff0c\u7136\u5f8c\u8f38\u5165\u8b8a\u91cf\u540d\u70ba <code>GOPATH<\/code>\uff0c\u8b8a\u91cf\u503c\u70ba\u4f60\u7684\u5de5\u4f5c\u76ee\u9304\uff0c\u4f8b\u5982 <code>C:UsersYourNamego<\/code>\u3002<\/li>\n<li>\u540c\u6a23\uff0c\u5c07 <code>%GOPATH%bin<\/code> \u6dfb\u52a0\u5230\u7cfb\u7d71\u7684 <code>PATH<\/code> \u8b8a\u91cf\u4e2d\u3002<\/li>\n<\/ol>\n<h2 id=\"%e4%bd%bf%e7%94%a8-gopath-%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-GuRtKgwySE\">\u4f7f\u7528 GOPATH \u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528 GOPATH \u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8a18\u4f4f\uff1a<\/p>\n<ul>\n<li>\u6240\u6709\u7684 Go \u6e90\u4ee3\u78bc\u5fc5\u9808\u653e\u5728 <code>GOPATH\/src<\/code> \u76ee\u9304\u4e0b\uff0c\u5426\u5247 Go \u7de8\u8b6f\u5668\u5c07\u7121\u6cd5\u627e\u5230\u5b83\u5011\u3002<\/li>\n<li>\u4f7f\u7528 <code>go get<\/code> \u547d\u4ee4\u6642\uff0cGo \u6703\u81ea\u52d5\u4e0b\u8f09\u4f9d\u8cf4\u5305\u4e26\u5c07\u5176\u653e\u5728 <code>GOPATH\/src<\/code> \u4e2d\u3002<\/li>\n<li>\u96a8\u8457 Go 1.11 \u7248\u672c\u7684\u63a8\u51fa\uff0cGo \u5f15\u5165\u4e86\u6a21\u584a\uff08modules\uff09\u7684\u6982\u5ff5\uff0c\u9019\u4f7f\u5f97 GOPATH \u7684\u4f7f\u7528\u8b8a\u5f97\u4e0d\u90a3\u9ebc\u5fc5\u8981\uff0c\u4f46\u4ecd\u7136\u662f\u8a31\u591a\u820a\u9805\u76ee\u548c\u5de5\u5177\u7684\u57fa\u790e\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-GuRtKgwySE\">\u7e3d\u7d50<\/h2>\n<p>GOPATH \u662f Go \u8a9e\u8a00\u958b\u767c\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\uff0c\u7406\u89e3\u5176\u7d50\u69cb\u548c\u914d\u7f6e\u5c0d\u65bc\u6709\u6548\u5730\u7ba1\u7406 Go \u9805\u76ee\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457 Go \u8a9e\u8a00\u7684\u767c\u5c55\uff0c\u6a21\u584a\u5316\u7684\u652f\u6301\u4f7f\u5f97\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u9748\u6d3b\u5730\u7ba1\u7406\u4f9d\u8cf4\uff0c\u4f46\u5c0d\u65bc\u521d\u5b78\u8005\u4f86\u8aaa\uff0c\u638c\u63e1 GOPATH \u7684\u4f7f\u7528\u4ecd\u7136\u662f\u5b78\u7fd2 Go \u7684\u57fa\u790e\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u90e8\u7f72\u4f60\u7684 Go \u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u4f60\u8f15\u9b06\u4e0a\u624b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u4e86\u89e3 Go \u8a9e\u8a00\u7684 GOPATH\uff0c\u638c\u63e1 Go \u8a9e\u8a00\u5de5\u4f5c\u76ee\u9304\u7684\u8a2d\u7f6e\u8207\u7ba1\u7406\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\u8207\u9805\u76ee\u7d44\u7e54\u80fd\u529b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-57686","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57686","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=57686"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57686\/revisions"}],"predecessor-version":[{"id":57687,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57686\/revisions\/57687"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=57686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=57686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=57686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}