{"id":9344,"date":"2024-06-26T23:30:24","date_gmt":"2024-06-26T15:30:24","guid":{"rendered":"\/?p=9344"},"modified":"2024-06-26T23:30:24","modified_gmt":"2024-06-26T15:30:24","slug":"%e4%bb%8e%e9%9b%b6%e5%bc%80%e5%a7%8b%e6%90%ad%e5%bb%bago%e8%af%ad%e8%a8%80%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"\/?p=9344","title":{"rendered":"\u4ece\u96f6\u5f00\u59cb\u642d\u5efaGo\u8bed\u8a00\u5f00\u53d1\u73af\u5883"},"content":{"rendered":"<h1>\u5b89\u88c5Go\u8bed\u8a00\u53ca\u642d\u5efaGo\u8bed\u8a00\u5f00\u53d1\u73af\u5883<\/h1>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>Go\u8bed\u8a001.14\u7248\u672c\u4e4b\u540e\u63a8\u8350\u4f7f\u7528go modules\u7ba1\u7406\u4f9d\u8d56\uff0c\u4e5f\u4e0d\u518d\u9700\u8981\u628a\u4ee3\u7801\u5199\u5728GOPATH\u76ee\u5f55\u4e0b\u4e86\uff0c\u4e4b\u524d\u65e7\u7248\u672c\u7684\u6559\u7a0b\u6233\u8fd9\u4e2a<a href=\"https:\/\/www.liwenzhou.com\/posts\/Go\/install_go_dev_old\/\">\u94fe\u63a5<\/a>\u3002<\/p>\n<h2>\u4e0b\u8f7d<\/h2>\n<h3>\u4e0b\u8f7d\u5730\u5740<\/h3>\n<p>Go\u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"https:\/\/golang.org\/dl\/\">https:\/\/golang.org\/dl\/<\/a><\/p>\n<p>Go\u5b98\u65b9\u955c\u50cf\u7ad9\uff08\u63a8\u8350\uff09\uff1a<a href=\"https:\/\/golang.google.cn\/dl\/\">https:\/\/golang.google.cn\/dl\/<\/a><\/p>\n<h3>\u7248\u672c\u7684\u9009\u62e9<\/h3>\n<p>Windows\u5e73\u53f0\u548cMac\u5e73\u53f0\u63a8\u8350\u4e0b\u8f7d\u53ef\u6267\u884c\u6587\u4ef6\u7248\uff0cLinux\u5e73\u53f0\u4e0b\u8f7d\u538b\u7f29\u6587\u4ef6\u7248\u3002<\/p>\n<p><strong>\u4e0b\u56fe\u4e2d\u7684\u7248\u672c\u53f7\u53ef\u80fd\u5e76\u4e0d\u662f\u6700\u65b0\u7684\uff0c\u4f46\u603b\u4f53\u6765\u8bf4\u5b89\u88c5\u6559\u7a0b\u662f\u7c7b\u4f3c\u7684\u3002Go\u8bed\u8a00\u66f4\u65b0\u8fed\u4ee3\u6bd4\u8f83\u5feb\uff0c\u63a8\u8350\u4f7f\u7528\u8f83\u65b0\u7248\u672c\uff0c\u4f53\u9a8c\u6700\u65b0\u7279\u6027\u3002<\/strong><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/download1.png\" alt=\"download1\" \/><\/p>\n<h2>\u5b89\u88c5<\/h2>\n<h3>Windows\u5b89\u88c5<\/h3>\n<p>\u6b64\u5b89\u88c5\u5b9e\u4f8b\u4ee5 <code>64\u4f4dWin10<\/code>\u7cfb\u7edf\u5b89\u88c5 <code>Go1.14.1\u53ef\u6267\u884c\u6587\u4ef6\u7248\u672c<\/code>\u4e3a\u4f8b\u3002<\/p>\n<p>\u5c06\u4e0a\u4e00\u6b65\u9009\u597d\u7684\u5b89\u88c5\u5305\u4e0b\u8f7d\u5230\u672c\u5730\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/download2.png\" alt=\"download2\" \/><\/p>\n<p>\u53cc\u51fb\u4e0b\u8f7d\u597d\u7684\u6587\u4ef6\uff0c\u7136\u540e\u6309\u7167\u4e0b\u56fe\u7684\u6b65\u9aa4\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/install01.png\" alt=\"install01\" \/><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/install02.png\" alt=\"install02\" \/><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/install03.png\" alt=\"install03\" \/><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/install04.png\" alt=\"install04\" \/><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/install05.png\" alt=\"install05\" \/><\/p>\n<h3>Linux\u4e0b\u5b89\u88c5<\/h3>\n<p>\u5982\u679c\u4e0d\u662f\u8981\u5728Linux\u5e73\u53f0\u6572go\u4ee3\u7801\u5c31\u4e0d\u9700\u8981\u5728Linux\u5e73\u53f0\u5b89\u88c5Go\uff0c\u6211\u4eec\u5f00\u53d1\u673a\u4e0a\u5199\u597d\u7684go\u4ee3\u7801\u53ea\u9700\u8981\u8de8\u5e73\u53f0\u7f16\u8bd1\uff08\u8be6\u89c1\u6587\u7ae0\u672b\u5c3e\u7684\u8de8\u5e73\u53f0\u7f16\u8bd1\uff09\u597d\u4e4b\u540e\u5c31\u53ef\u4ee5\u62f7\u8d1d\u5230Linux\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u4e86\uff0c\u8fd9\u4e5f\u662fgo\u7a0b\u5e8f\u8de8\u5e73\u53f0\u6613\u90e8\u7f72\u7684\u4f18\u52bf\u3002<\/p>\n<p>\u6211\u4eec\u5728\u7248\u672c\u9009\u62e9\u9875\u9762\u9009\u62e9\u5e76\u4e0b\u8f7d\u597d<code>go1.14.1.linux-amd64.tar.gz<\/code>\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-bash\">wget https:\/\/dl.google.com\/go\/go1.14.1.linux-amd64.tar.gz<\/code><\/pre>\n<p>\u5c06\u4e0b\u8f7d\u597d\u7684\u6587\u4ef6\u89e3\u538b\u5230<code>\/usr\/local<\/code>\u76ee\u5f55\u4e0b\uff1a<\/p>\n<pre><code class=\"language-bash\">tar -zxvf go1.14.1.linux-amd64.tar.gz -C \/usr\/local  # \u89e3\u538b<\/code><\/pre>\n<p>\u5982\u679c\u63d0\u793a\u6ca1\u6709\u6743\u9650\uff0c\u52a0\u4e0a<code>sudo<\/code>\u4ee5root\u7528\u6237\u7684\u8eab\u4efd\u518d\u8fd0\u884c\u3002\u6267\u884c\u5b8c\u5c31\u53ef\u4ee5\u5728<code>\/usr\/local\/<\/code>\u4e0b\u770b\u5230<code>go<\/code>\u76ee\u5f55\u4e86\u3002<\/p>\n<p>\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff1a Linux\u4e0b\u6709\u4e24\u4e2a\u6587\u4ef6\u53ef\u4ee5\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u5176\u4e2d<code>\/etc\/profile<\/code>\u662f\u5bf9\u6240\u6709\u7528\u6237\u751f\u6548\u7684\uff1b<code>$HOME\/.profile<\/code>\u662f\u5bf9\u5f53\u524d\u7528\u6237\u751f\u6548\u7684\uff0c\u6839\u636e\u81ea\u5df1\u7684\u60c5\u51b5\u81ea\u884c\u9009\u62e9\u4e00\u4e2a\u6587\u4ef6\u6253\u5f00\uff0c\u6dfb\u52a0\u5982\u4e0b\u4e24\u884c\u4ee3\u7801\uff0c\u4fdd\u5b58\u9000\u51fa\u3002<\/p>\n<pre><code class=\"language-bash\">export GOROOT=\/usr\/local\/go\nexport PATH=$PATH:$GOROOT\/bin<\/code><\/pre>\n<p>\u4fee\u6539<code>\/etc\/profile<\/code>\u540e\u8981\u91cd\u542f\u751f\u6548\uff0c\u4fee\u6539<code>$HOME\/.profile<\/code>\u540e\u4f7f\u7528source\u547d\u4ee4\u52a0\u8f7d<code>$HOME\/.profile<\/code>\u6587\u4ef6\u5373\u53ef\u751f\u6548\u3002 \u68c0\u67e5\uff1a<\/p>\n<pre><code class=\"language-bash\">~ go version\ngo version go1.14.1 linux\/amd64<\/code><\/pre>\n<h3>Mac\u4e0b\u5b89\u88c5<\/h3>\n<p>\u4e0b\u8f7d\u53ef\u6267\u884c\u6587\u4ef6\u7248\uff0c\u76f4\u63a5\u70b9\u51fb<strong>\u4e0b\u4e00\u6b65<\/strong>\u5b89\u88c5\u5373\u53ef\uff0c\u9ed8\u8ba4\u4f1a\u5c06go\u5b89\u88c5\u5230<code>\/usr\/local\/go<\/code>\u76ee\u5f55\u4e0b\u3002<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/mac_install_go.png\" alt=\"Mac\u5b89\u88c5Go\" \/><\/p>\n<h3>\u68c0\u67e5<\/h3>\n<p>\u4e0a\u4e00\u6b65\u5b89\u88c5\u8fc7\u7a0b\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u7a97\u53e3\uff0c\u8f93\u5165<code>go version<\/code>\u547d\u4ee4\uff0c\u67e5\u770b\u5b89\u88c5\u7684Go\u7248\u672c\u3002<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/install06.png\" alt=\"install06\" \/><\/p>\n<h2>GOROOT\u548cGOPATH<\/h2>\n<p><code>GOROOT<\/code>\u548c<code>GOPATH<\/code>\u90fd\u662f\u73af\u5883\u53d8\u91cf\uff0c\u5176\u4e2d<code>GOROOT<\/code>\u662f\u6211\u4eec\u5b89\u88c5go\u5f00\u53d1\u5305\u7684\u8def\u5f84\uff0c\u800c\u4eceGo 1.8\u7248\u672c\u5f00\u59cb\uff0cGo\u5f00\u53d1\u5305\u5728\u5b89\u88c5\u5b8c\u6210\u540e\u4f1a\u4e3a<code>GOPATH<\/code>\u8bbe\u7f6e\u4e00\u4e2a\u9ed8\u8ba4\u76ee\u5f55\uff0c\u5e76\u4e14\u5728Go1.14\u53ca\u4e4b\u540e\u7684\u7248\u672c\u4e2d\u542f\u7528\u4e86Go Module\u6a21\u5f0f\u4e4b\u540e\uff0c\u4e0d\u4e00\u5b9a\u975e\u8981\u5c06\u4ee3\u7801\u5199\u5230GOPATH\u76ee\u5f55\u4e0b\uff0c\u6240\u4ee5\u4e5f\u5c31<strong>\u4e0d\u9700\u8981\u6211\u4eec\u518d\u81ea\u5df1\u914d\u7f6eGOPATH<\/strong>\u4e86\uff0c\u4f7f\u7528\u9ed8\u8ba4\u7684\u5373\u53ef\u3002<\/p>\n<p>\u60f3\u8981\u67e5\u770b\u4f60\u7535\u8111\u4e0a\u7684<code>GOPATH<\/code>\u8def\u5f84\uff0c\u53ea\u9700\u8981\u6253\u5f00\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u56de\u8f66\uff1a<\/p>\n<pre><code class=\"language-bash\">go env<\/code><\/pre>\n<p>\u5728\u7ec8\u7aef\u8f93\u51fa\u7684\u5185\u5bb9\u4e2d\u627e\u5230<code>GOPATH<\/code>\u5bf9\u5e94\u7684\u5177\u4f53\u8def\u5f84\u3002<\/p>\n<h3>GOPROXY \u975e\u5e38\u91cd\u8981<\/h3>\n<p>Go1.14\u7248\u672c\u4e4b\u540e\uff0c\u90fd\u63a8\u8350\u4f7f\u7528<code>go mod<\/code>\u6a21\u5f0f\u6765\u7ba1\u7406\u4f9d\u8d56\u73af\u5883\u4e86\uff0c\u4e5f\u4e0d\u518d\u5f3a\u5236\u6211\u4eec\u628a\u4ee3\u7801\u5fc5\u987b\u5199\u5728<code>GOPATH<\/code>\u4e0b\u9762\u7684src\u76ee\u5f55\u4e86\uff0c\u4f60\u53ef\u4ee5\u5728\u4f60\u7535\u8111\u7684\u4efb\u610f\u4f4d\u7f6e\u7f16\u5199go\u4ee3\u7801\u3002\uff08\u7f51\u4e0a\u6709\u4e9b\u6559\u7a0b\u9002\u7528\u4e8e1.11\u7248\u672c\u4e4b\u524d\u3002\uff09<\/p>\n<p>\u9ed8\u8ba4GoPROXY\u914d\u7f6e\u662f\uff1a<code>GOPROXY=https:\/\/proxy.golang.org,direct<\/code>\uff0c\u7531\u4e8e\u56fd\u5185\u8bbf\u95ee\u4e0d\u5230<code>https:\/\/proxy.golang.org<\/code>\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u6362\u4e00\u4e2aPROXY\uff0c\u8fd9\u91cc\u63a8\u8350\u4f7f\u7528<code>https:\/\/goproxy.io<\/code>\u6216<code>https:\/\/goproxy.cn<\/code>\u3002<\/p>\n<p>\u53ef\u4ee5\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u4fee\u6539GOPROXY\uff1a<\/p>\n<pre><code class=\"language-bash\">go env -w GOPROXY=https:\/\/goproxy.cn,direct<\/code><\/pre>\n<h2>Go\u5f00\u53d1\u7f16\u8f91\u5668<\/h2>\n<p>Go\u91c7\u7528\u7684\u662fUTF-8\u7f16\u7801\u7684\u6587\u672c\u6587\u4ef6\u5b58\u653e\u6e90\u4ee3\u7801\uff0c\u7406\u8bba\u4e0a\u4f7f\u7528\u4efb\u4f55\u4e00\u6b3e\u6587\u672c\u7f16\u8f91\u5668\u90fd\u53ef\u4ee5\u505aGo\u8bed\u8a00\u5f00\u53d1\uff0c\u8fd9\u91cc\u63a8\u8350\u4f7f\u7528<code>VS Code<\/code>\u548c<code>Goland<\/code>\u3002 <code>VS Code<\/code>\u662f\u5fae\u8f6f\u5f00\u6e90\u7684\u7f16\u8f91\u5668\uff0c\u800c<code>Goland<\/code>\u662fjetbrains\u51fa\u54c1\u7684\u4ed8\u8d39IDE\u3002<\/p>\n<p>\u6211\u4eec\u8fd9\u91cc\u4f7f\u7528<code>VS Code<\/code> \u52a0\u63d2\u4ef6\u505a\u4e3ago\u8bed\u8a00\u7684\u5f00\u53d1\u5de5\u5177\u3002<\/p>\n<h3>VS Code\u4ecb\u7ecd<\/h3>\n<p><code>VS Code<\/code>\u5168\u79f0<code>Visual Studio Code<\/code>\uff0c\u662f\u5fae\u8f6f\u516c\u53f8\u5f00\u6e90\u7684\u4e00\u6b3e<strong>\u514d\u8d39<\/strong>\u73b0\u4ee3\u5316\u8f7b\u91cf\u7ea7\u4ee3\u7801\u7f16\u8f91\u5668\uff0c\u652f\u6301\u51e0\u4e4e\u6240\u6709\u4e3b\u6d41\u7684\u5f00\u53d1\u8bed\u8a00\u7684\u8bed\u6cd5\u9ad8\u4eae\u3001\u667a\u80fd\u4ee3\u7801\u8865\u5168\u3001\u81ea\u5b9a\u4e49\u70ed\u952e\u3001\u62ec\u53f7\u5339\u914d\u3001\u4ee3\u7801\u7247\u6bb5\u3001\u4ee3\u7801\u5bf9\u6bd4 Diff\u3001GIT \u7b49\u7279\u6027\uff0c\u652f\u6301\u63d2\u4ef6\u6269\u5c55\uff0c\u652f\u6301 Win\u3001Mac \u4ee5\u53ca Linux\u5e73\u53f0\u3002<\/p>\n<p>\u867d\u7136\u4e0d\u5982\u67d0\u4e9bIDE\u529f\u80fd\u5f3a\u5927\uff0c\u4f46\u662f\u5b83\u6dfb\u52a0Go\u6269\u5c55\u63d2\u4ef6\u540e\u5df2\u7ecf\u8db3\u591f\u80dc\u4efb\u6211\u4eec\u65e5\u5e38\u7684Go\u5f00\u53d1\u3002<\/p>\n<h3>\u4e0b\u8f7d\u4e0e\u5b89\u88c5<\/h3>\n<p><code>VS Code<\/code>\u5b98\u65b9\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"https:\/\/code.visualstudio.com\/Download\">https:\/\/code.visualstudio.com\/Download<\/a><\/p>\n<p>\u4e09\u5927\u4e3b\u6d41\u5e73\u53f0\u90fd\u652f\u6301\uff0c\u8bf7\u6839\u636e\u81ea\u5df1\u7684\u7535\u8111\u5e73\u53f0\u9009\u62e9\u5bf9\u5e94\u7684\u5b89\u88c5\u5305\u3002<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode_home.png\" alt=\"vscode_home\" \/>\u53cc\u51fb\u4e0b\u8f7d\u597d\u7684\u5b89\u88c5\u6587\u4ef6\uff0c\u53cc\u51fb\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<h3>\u914d\u7f6e<\/h3>\n<h4>\u5b89\u88c5\u4e2d\u6587\u7b80\u4f53\u63d2\u4ef6<\/h4>\n<p>\u70b9\u51fb\u5de6\u4fa7\u83dc\u5355\u680f\u6700\u540e\u4e00\u9879<code>\u7ba1\u7406\u6269\u5c55<\/code>\uff0c\u5728<code>\u641c\u7d22\u6846<\/code>\u4e2d\u8f93\u5165<code>chinese<\/code> \uff0c\u9009\u4e2d\u7ed3\u679c\u5217\u8868\u7b2c\u4e00\u9879\uff0c\u70b9\u51fb<code>install<\/code>\u5b89\u88c5\u3002<\/p>\n<p>\u5b89\u88c5\u5b8c\u6bd5\u540e\u53f3\u4e0b\u89d2\u4f1a\u63d0\u793a<code>\u91cd\u542fVS Code<\/code>\uff0c\u91cd\u542f\u4e4b\u540e\u4f60\u7684VS Code\u5c31\u663e\u793a\u4e2d\u6587\u5566\uff01<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode1.gif\" alt=\"\u5b89\u88c5\u7b80\u4f53\u4e2d\u6587\u63d2\u4ef6\" \/><code>VSCode<\/code>\u4e3b\u754c\u9762\u4ecb\u7ecd\uff1a<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode_menu.png\" alt=\"vscode_menu\" \/><\/p>\n<h4>\u5b89\u88c5go\u6269\u5c55<\/h4>\n<p>\u73b0\u5728\u6211\u4eec\u8981\u4e3a\u6211\u4eec\u7684VS Code\u7f16\u8f91\u5668\u5b89\u88c5<code>Go<\/code>\u6269\u5c55\u63d2\u4ef6\uff0c\u8ba9\u5b83\u652f\u6301Go\u8bed\u8a00\u5f00\u53d1\u3002<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode_plugin.png\" alt=\"\u5b89\u88c5go\u6269\u5c55\u56fe\" \/><\/p>\n<h2>\u7b2c\u4e00\u4e2aGo\u7a0b\u5e8f<\/h2>\n<h3>Hello World<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u6765\u521b\u5efa\u7b2c\u4e00\u4e2aGo\u9879\u76ee\u2014\u2014<code>hello<\/code>\u3002\u5728\u6211\u4eec\u684c\u9762\u521b\u5efa\u4e00\u4e2a<code>hello<\/code>\u76ee\u5f55\u3002<\/p>\n<h4>go mod init<\/h4>\n<p>\u4f7f\u7528go module\u6a21\u5f0f\u65b0\u5efa\u9879\u76ee\u65f6\uff0c\u6211\u4eec<strong>\u9700\u8981<\/strong>\u901a\u8fc7<code>go mod init \u9879\u76ee\u540d<\/code>\u547d\u4ee4\u5bf9\u9879\u76ee\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u8be5\u547d\u4ee4\u4f1a\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u751f\u6210<code>go.mod<\/code>\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u4f7f\u7528<code>hello<\/code>\u4f5c\u4e3a\u6211\u4eec\u7b2c\u4e00\u4e2aGo\u9879\u76ee\u7684\u540d\u79f0\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre><code class=\"language-bash\">go mod init hello<\/code><\/pre>\n<h4>\u7f16\u5199\u4ee3\u7801<\/h4>\n<p>\u63a5\u4e0b\u6765\u5728\u8be5\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a<code>main.go<\/code>\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-go\">package main  \/\/ \u58f0\u660e main \u5305\uff0c\u8868\u660e\u5f53\u524d\u662f\u4e00\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\n\nimport &quot;fmt&quot;  \/\/ \u5bfc\u5165\u5185\u7f6e fmt \u5305\n\nfunc main(){  \/\/ main\u51fd\u6570\uff0c\u662f\u7a0b\u5e8f\u6267\u884c\u7684\u5165\u53e3\n    fmt.Println(&quot;Hello World!&quot;)  \/\/ \u5728\u7ec8\u7aef\u6253\u5370 Hello World!\n}<\/code><\/pre>\n<p><strong>\u975e\u5e38\u91cd\u8981\uff01\uff01\uff01<\/strong> \u5982\u679c\u6b64\u65f6VS Code\u53f3\u4e0b\u89d2\u5f39\u51fa\u63d0\u793a\u8ba9\u4f60\u5b89\u88c5\u63d2\u4ef6\uff0c\u52a1\u5fc5\u70b9 <strong>install all<\/strong> \u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<p>\u8fd9\u4e00\u6b65\u9700\u8981\u5148\u6267\u884c\u5b8c\u4e0a\u9762\u63d0\u5230\u7684<code>go env -w GOPROXY=https:\/\/goproxy.cn,direct<\/code>\u547d\u4ee4\u914d\u7f6e\u597d<code>GOPROXY<\/code>\u3002<\/p>\n<h3>\u7f16\u8bd1<\/h3>\n<p><code>go build<\/code>\u547d\u4ee4\u8868\u793a\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>\u5728hello\u76ee\u5f55\u4e0b\u6267\u884c\uff1a<\/p>\n<pre><code class=\"language-bash\">go build<\/code><\/pre>\n<p>\u7f16\u8bd1\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4f1a\u4fdd\u5b58\u5728\u6267\u884c\u7f16\u8bd1\u547d\u4ee4\u7684\u5f53\u524d\u76ee\u5f55\u4e0b\uff0c\u5982\u679c\u662f<code>Windows<\/code>\u5e73\u53f0\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u627e\u5230<code>hello.exe<\/code>\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p>\u53ef\u5728\u7ec8\u7aef\u76f4\u63a5\u6267\u884c\u8be5<code>hello.exe<\/code>\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-bash\">c:\\desktop\\hello&gt;hello.exe\nHello World!<\/code><\/pre>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>-o<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u7f16\u8bd1\u540e\u5f97\u5230\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u540d\u5b57\u3002<\/p>\n<pre><code class=\"language-bash\">go build -o heiheihei.exe<\/code><\/pre>\n<h3>Windows\u4e0bVSCode\u5207\u6362cmd.exe\u4f5c\u4e3a\u9ed8\u8ba4\u7ec8\u7aef<\/h3>\n<p>\u5982\u679c\u4f60\u6253\u5f00VS Code\u7684\u7ec8\u7aef\u754c\u9762\u51fa\u73b0\u5982\u4e0b\u56fe\u573a\u666f\uff08\u6ce8\u610f\u89c2\u5bdf\u7ea2\u6846\u5708\u4e2d\u90e8\u5206\uff09\uff0c\u90a3\u4e48\u4f60\u7684<code>VS Code<\/code>\u6b64\u65f6\u6b63\u4f7f\u7528<code>powershell<\/code>\u4f5c\u4e3a\u9ed8\u8ba4\u7ec8\u7aef\uff1a<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode_shell1.png\" alt=\"vscode shell\u914d\u7f6e1\" \/>\u5341\u5206\u63a8\u8350\u4f60\u6309\u7167\u4e0b\u9762\u7684\u6b65\u9aa4\uff0c\u9009\u62e9<code>cmd.exe<\/code>\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u7ec8\u7aef\u5de5\u5177\uff1a<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode_shell2.png\" alt=\"vscode shell\u914d\u7f6e2\" \/>\u6b64\u65f6\uff0cVS Code\u6b63\u4e0a\u65b9\u4e2d\u95f4\u4f4d\u7f6e\u4f1a\u5f39\u51fa\u5982\u4e0b\u754c\u9762\uff0c\u53c2\u7167\u4e0b\u56fe\u632a\u52a8\u9f20\u6807\u4f7f\u5149\u6807\u9009\u4e2d\u540e\u7f00\u4e3a<code>cmd.exe<\/code>\u7684\u90a3\u4e00\u4e2a\uff0c\u7136\u540e\u70b9\u51fb\u9f20\u6807\u5de6\u952e\u3002<\/p>\n<p>\u6700\u540e<strong>\u91cd\u542fVS Code\u4e2d\u5df2\u7ecf\u6253\u5f00\u7684\u7ec8\u7aef<\/strong>\u6216\u8005<strong>\u76f4\u63a5\u91cd\u542fVS Code<\/strong>\u5c31\u53ef\u4ee5\u4e86\u3002<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode_shell3.png\" alt=\"vscode shell\u914d\u7f6e3\" \/>\u5982\u679c\u6ca1\u6709\u51fa\u73b0\u4e0b\u62c9\u4e09\u89d2\uff0c\u4e5f\u6ca1\u6709\u5173\u7cfb\uff0c\u6309\u4e0b<code>Ctrl+Shift+P<\/code>\uff0cVS Code\u6b63\u4e0a\u65b9\u4f1a\u51fa\u73b0\u4e00\u4e2a\u6846\uff0c\u4f60\u6309\u7167\u4e0b\u56fe\u8f93\u5165<code>shell<\/code>\uff0c\u7136\u540e\u70b9\u51fb\u6307\u5b9a\u9009\u9879\u5373\u53ef\u51fa\u73b0\u4e0a\u9762\u7684\u754c\u9762\u4e86\u3002<img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/vscode_shell4.png\" alt=\"vscode shell\u914d\u7f6e4\" \/><\/p>\n<h3>go run<\/h3>\n<p><code>go run main.go<\/code>\u4e5f\u53ef\u4ee5\u6267\u884c\u7a0b\u5e8f\uff0c\u8be5\u547d\u4ee4\u672c\u8d28\u4e0a\u662f\u5148\u5728\u4e34\u65f6\u76ee\u5f55\u7f16\u8bd1\u7a0b\u5e8f\u7136\u540e\u518d\u6267\u884c\u3002<\/p>\n<blockquote>\n<p>\u5982\u679c\u4f60\u4e0d\u6e05\u695a\u4e0a\u65b9\u5173\u4e8e<code>go run<\/code>\u6267\u884c\u673a\u5236\u7684\u63cf\u8ff0\uff0c\u90a3\u4e48\u4f60\u6700\u597d\u4eca\u540e\u90fd\u4f7f\u7528<code>go build<\/code>\u7f16\u8bd1\u518d\u6267\u884c\u3002<\/p>\n<\/blockquote>\n<h3>go install<\/h3>\n<p><code>go install<\/code>\u8868\u793a\u5b89\u88c5\u7684\u610f\u601d\uff0c\u5b83\u5148\u7f16\u8bd1\u6e90\u4ee3\u7801\u5f97\u5230\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u7136\u540e\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u79fb\u52a8\u5230<code>GOPATH<\/code>\u7684bin\u76ee\u5f55\u4e0b\u3002\u56e0\u4e3a\u6211\u4eec<strong>\u628a<code>GOPATH<\/code>\u4e0b\u7684<code>bin<\/code>\u76ee\u5f55\u6dfb\u52a0\u5230\u4e86\u73af\u5883\u53d8\u91cf\u4e2d<\/strong>\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u4efb\u610f\u5730\u65b9\u76f4\u63a5\u6267\u884c\u53ef\u6267\u884c\u6587\u4ef6\u4e86\u3002<\/p>\n<h3>\u8de8\u5e73\u53f0\u7f16\u8bd1<\/h3>\n<p>\u9ed8\u8ba4\u6211\u4eec<code>go build<\/code>\u7684\u53ef\u6267\u884c\u6587\u4ef6\u90fd\u662f\u5f53\u524d\u64cd\u4f5c\u7cfb\u7edf\u53ef\u6267\u884c\u7684\u6587\u4ef6\uff0cGo\u8bed\u8a00\u652f\u6301\u8de8\u5e73\u53f0\u7f16\u8bd1\u2014\u2014\u5728\u5f53\u524d\u5e73\u53f0\uff08\u4f8b\u5982Windows\uff09\u4e0b\u7f16\u8bd1\u5176\u4ed6\u5e73\u53f0\uff08\u4f8b\u5982Linux\uff09\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<h4>Windows\u7f16\u8bd1Linux\u53ef\u6267\u884c\u6587\u4ef6<\/h4>\n<p>\u5982\u679c\u6211\u60f3\u5728Windows\u4e0b\u7f16\u8bd1\u4e00\u4e2aLinux\u4e0b\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u90a3\u9700\u8981\u600e\u4e48\u505a\u5462\uff1f\u53ea\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u6307\u5b9a\u76ee\u6807\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e73\u53f0\u548c\u5904\u7406\u5668\u67b6\u6784\u5373\u53ef\u3002<\/p>\n<blockquote>\n<p>\u6ce8\u610f\uff1a\u65e0\u8bba\u4f60\u5728Windows\u7535\u8111\u4e0a\u4f7f\u7528VsCode\u7f16\u8f91\u5668\u8fd8\u662fGoland\u7f16\u8f91\u5668\uff0c\u90fd\u8981\u6ce8\u610f\u4f60\u4f7f\u7528\u7684\u7ec8\u7aef\u7c7b\u578b\uff0c\u56e0\u4e3a\u4e0d\u540c\u7684\u7ec8\u7aef\u4e0b\u547d\u4ee4\u4e0d\u4e00\u6837\uff01\uff01\uff01\u76ee\u524d\u7684Windows\u901a\u5e38\u9ed8\u8ba4\u4f7f\u7528\u7684\u662f<code>PowerShell<\/code>\u7ec8\u7aef\u3002<\/p>\n<\/blockquote>\n<p>\u5982\u679c\u4f60\u7684<code>Windows<\/code>\u4f7f\u7528\u7684\u662f<code>cmd<\/code>\uff0c\u90a3\u4e48\u6309\u5982\u4e0b\u65b9\u5f0f\u6307\u5b9a\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<pre><code class=\"language-bash\">SET CGO_ENABLED=0  \/\/ \u7981\u7528CGO\nSET GOOS=linux  \/\/ \u76ee\u6807\u5e73\u53f0\u662flinux\nSET GOARCH=amd64  \/\/ \u76ee\u6807\u5904\u7406\u5668\u67b6\u6784\u662famd64<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u7684<code>Windows<\/code>\u4f7f\u7528\u7684\u662f<code>PowerShell<\/code>\u7ec8\u7aef\uff0c\u90a3\u4e48\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u7684\u8bed\u6cd5\u4e3a<\/p>\n<pre><code class=\"language-bash\">$ENV:CGO_ENABLED=0\n$ENV:GOOS=&quot;linux&quot;\n$ENV:GOARCH=&quot;amd64&quot;<\/code><\/pre>\n<p>\u5728\u4f60\u7684<code>Windows<\/code>\u7ec8\u7aef\u4e0b\u6267\u884c\u5b8c\u4e0a\u8ff0\u547d\u4ee4\u540e\uff0c\u518d\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff0c\u5f97\u5230\u7684\u5c31\u662f\u80fd\u591f\u5728Linux\u5e73\u53f0\u8fd0\u884c\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e86\u3002<\/p>\n<pre><code class=\"language-bash\">go build<\/code><\/pre>\n<h4>Windows\u7f16\u8bd1Mac\u53ef\u6267\u884c\u6587\u4ef6<\/h4>\n<p>Windows\u4e0b\u7f16\u8bd1Mac\u5e73\u53f064\u4f4d\u53ef\u6267\u884c\u7a0b\u5e8f\uff1a<\/p>\n<p>cmd\u7ec8\u7aef\u4e0b\u6267\u884c\uff1a<\/p>\n<pre><code class=\"language-bash\">SET CGO_ENABLED=0\nSET GOOS=darwin\nSET GOARCH=amd64\ngo build<\/code><\/pre>\n<p>PowerShell\u7ec8\u7aef\u4e0b\u6267\u884c\uff1a<\/p>\n<pre><code class=\"language-bash\">$ENV:CGO_ENABLED=0\n$ENV:GOOS=&quot;darwin&quot;\n$ENV:GOARCH=&quot;amd64&quot;\ngo build<\/code><\/pre>\n<h4>Mac\u7f16\u8bd1Linux\u53ef\u6267\u884c\u6587\u4ef6<\/h4>\n<p>Mac\u7535\u8111\u7f16\u8bd1\u5f97\u5230Linux\u5e73\u53f064\u4f4d\u53ef\u6267\u884c\u7a0b\u5e8f\uff1a<\/p>\n<pre><code class=\"language-bash\">CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build<\/code><\/pre>\n<h4>Mac\u7f16\u8bd1Windows\u53ef\u6267\u884c\u6587\u4ef6<\/h4>\n<p>Mac\u7535\u8111\u7f16\u8bd1\u5f97\u5230Windows\u5e73\u53f064\u4f4d\u53ef\u6267\u884c\u7a0b\u5e8f\uff1a<\/p>\n<pre><code class=\"language-bash\">CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build<\/code><\/pre>\n<h4>Linux\u7f16\u8bd1Mac\u53ef\u6267\u884c\u6587\u4ef6<\/h4>\n<p>Linux\u5e73\u53f0\u4e0b\u7f16\u8bd1Mac\u5e73\u53f064\u4f4d\u53ef\u6267\u884c\u7a0b\u5e8f\uff1a<\/p>\n<pre><code class=\"language-bash\">CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build<\/code><\/pre>\n<h4>Linux\u7f16\u8bd1Windows\u53ef\u6267\u884c\u6587\u4ef6<\/h4>\n<p>Linux\u5e73\u53f0\u4e0b\u7f16\u8bd1Windows\u5e73\u53f064\u4f4d\u53ef\u6267\u884c\u7a0b\u5e8f\uff1a<\/p>\n<pre><code class=\"language-bash\">CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build<\/code><\/pre>\n<p>\u73b0\u5728\uff0c\u5f00\u542f\u4f60\u7684Go\u8bed\u8a00\u5b66\u4e60\u4e4b\u65c5\u5427\u3002\u4eba\u751f\u82e6\u77ed\uff0clet\u2019s Go.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5Go\u8bed\u8a00\u53ca\u642d\u5efaGo\u8bed\u8a00\u5f00\u53d1\u73af\u5883 \u6ce8\u610f\uff1aGo\u8bed\u8a001.14\u7248\u672c\u4e4b\u540e\u63a8\u8350\u4f7f\u7528go modules\u7ba1\u7406\u4f9d\u8d56\uff0c\u4e5f\u4e0d\u518d\u9700\u8981\u628a\u4ee3\u7801\u5199\u5728GOPATH   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[111],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9344"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9344"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9344\/revisions"}],"predecessor-version":[{"id":9345,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9344\/revisions\/9345"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9344"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}