id: cc71e2dfe76744b8a334e36cea8ca974
parent_id: 
item_type: 1
item_id: c025e3ca810043e5b9693fa9ed1e8bf1
item_updated_time: 1764345475075
title_diff: "[{\"diffs\":[[1,\"go环境变量配置 (GOROOT和GOPATH)\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":24}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>go环境变量配置 (GOROOT和GOPATH)</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"7077\\\"></a>\\\r\\\n<h1>go环境变量配置 (GOROOT和GOPATH)</h1>\\\r\\\n\\\r\\\n<div><span>\\\n  <div style=\\\"--en-clipped-content:article\\\">\\\n<div><br/></div><div style=\\\"font-size: 16px; display:block; min-width: 100%; position: relative;\\\"> <div style=\\\"font-family:sans-serif;text-size-adjust:100%;box-sizing:border-box;font-size:10px;-webkit-tap-highlight-color:transparent;\\\"><div style=\\\"box-sizing:border-box;line-height:1.42857;background-color:rgb(255, 255, 255);min-width:768px;font-size:17px;color:rgb(51, 51, 51);font-family:-apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;\\\"><div style=\\\"box-sizing:border-box;\\\"><div style=\\\"box-sizing:border-box;\\\"><div style=\\\"box-sizing:border-box;\\\">\\\n        <h1 style=\\\"box-sizing:border-box;color:inherit;font-size:34px;margin:20px 0px 0px;font-family:-apple-system, &quot;SF UI Display&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-weight:700;line-height:1.3;word-break:break-word;\\\">go环境变量配置 (GOROOT和GOPATH)</h1>\\\n\\\n        \\\n        <div style=\\\"box-sizing:border-box;margin:30px 0px 40px;\\\">\\\n          <a href=\\\"https://www.jianshu.com/u/5c920c5e11be\\\" style=\\\"background-color:transparent;box-sizing:border-box;text-decoration:none;color:rgb(51, 51, 51);cursor:pointer;vertical-align:middle;width:48px;height:48px;display:inline-block;\\\">\\\n            <img src=\\\"go环境变量配置 (GOROOT和GOPATH)_files/96\\\" type=\\\"image/png\\\" data-filename=\\\"96\\\" height=\\\"46\\\" style=\\\"box-sizing:border-box;vertical-align:middle;width:100%;height:100%;border-radius:50%;border:1px solid rgb(221, 221, 221);\\\" width=\\\"46\\\"/>\\\n</a>          <div style=\\\"box-sizing:border-box;vertical-align:middle;display:inline-block;margin-left:8px;\\\">\\\n            <span style=\\\"box-sizing:border-box;margin-right:3px;font-size:16px;vertical-align:middle;\\\"><a href=\\\"https://www.jianshu.com/u/5c920c5e11be\\\" style=\\\"background-color:transparent;box-sizing:border-box;text-decoration:none;color:rgb(51, 51, 51);cursor:pointer;\\\">元亨利贞o</a></span>\\\n            \\\n            <a style=\\\"box-sizing:border-box;text-decoration:none;display:inline-block;margin-bottom:0px;text-align:center;vertical-align:middle;touch-action:manipulation;background-image:none;border:1px solid transparent;white-space:nowrap;user-select:none;cursor:pointer;background-color:rgb(66, 192, 46);color:rgb(255, 255, 255);border-radius:40px;font-weight:400;line-height:normal;border-color:rgb(66, 192, 46);padding:0px 7px 0px 5px;font-size:12px;\\\"><i style=\\\"box-sizing:border-box;font-size:inherit;font-style:normal;-webkit-font-smoothing:antialiased;font-family:iconfont;font-weight:400;\\\"><span style=\\\"font-size:inherit;font-style:normal;font-family:iconfont;font-weight:400;\\\"></span></i><span style=\\\"box-sizing:border-box;margin-left:2px;display:inline;\\\">关注</span></a>\\\n            \\\n            <div style=\\\"box-sizing:border-box;margin-top:5px;font-size:12px;color:rgb(150, 150, 150);\\\">\\\n              \\\n                <span style=\\\"box-sizing:border-box;padding-right:5px;color:rgb(234, 111, 90);\\\">\\\n                  <i style=\\\"box-sizing:border-box;font-size:inherit;font-style:normal;-webkit-font-smoothing:antialiased;font-family:iconfont;font-weight:400;\\\"><span style=\\\"font-size:inherit;font-style:normal;font-family:iconfont;font-weight:400;\\\"></span></i> 0.1\\\n                </span>\\\n              \\\n                <span style=\\\"box-sizing:border-box;padding-right:5px;\\\" title=\\\"\\\">2016.03.31 17:49*</span>\\\n              <span style=\\\"box-sizing:border-box;padding-right:5px;\\\">字数 498</span>\\\n            <span style=\\\"box-sizing:border-box;padding-right:5px;\\\">阅读 95137</span><span style=\\\"box-sizing:border-box;padding-right:5px;\\\">评论 11</span><span style=\\\"box-sizing:border-box;padding-right:5px;\\\">喜欢 12</span></div>\\\n          </div>\\\n          \\\n        </div>\\\n\\\n\\\n        \\\n        <div style=\\\"box-sizing:border-box;color:rgb(47, 47, 47);font-size:16px;font-weight:400;line-height:1.7;word-break:break-word;\\\">\\\n          <div style=\\\"box-sizing:border-box;\\\">\\\n            <hr style=\\\"height:0px;box-sizing:border-box;border-width:1px 0px 0px;border-right-style:initial;border-bottom-style:initial;border-left-style:initial;border-right-color:initial;border-bottom-color:initial;border-left-color:initial;border-image:initial;margin:0px 0px 20px;border-top:1px solid rgb(221, 221, 221);\\\"/>\\\n<ol style=\\\"box-sizing:border-box;padding:0px;margin:-5px 0px 20px 20px;word-break:break-word;\\\">\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">GOROOT就是go的安装路径<br style=\\\"box-sizing:border-box;\\\"/>\\\n在~/.bash_profile中添加下面语句:</li>\\\n</ol>\\\n<pre style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;margin:0px 0px 10px;line-height:1.42857;border:1px solid rgb(204, 204, 204);overflow-x:auto;background:rgb(40, 44, 52);display:block;color:rgb(171, 178, 191);margin-bottom:20px;white-space:pre;overflow:auto;font-size:13px;overflow-wrap:normal;border-radius:4px;padding:15px;word-break:break-word;\\\"><code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:inherit;border-radius:0px;border:none;vertical-align:middle;font-size:13px;background-color:transparent;padding:0px;white-space:pre;\\\">GOROOT=/usr/<span style=\\\"box-sizing:border-box;color:rgb(230, 192, 123);\\\">local</span>/go\\\n<span style=\\\"box-sizing:border-box;color:rgb(230, 192, 123);\\\">export</span> GOROOT\\\n</code></pre>\\\n<p style=\\\"box-sizing:border-box;margin:0px 0px 25px;word-break:break-word;\\\">当然, 要执行go命令和go工具, 就要配置go的可执行文件的路径:<br style=\\\"box-sizing:border-box;\\\"/>\\\n操作如下:<br style=\\\"box-sizing:border-box;\\\"/>\\\n在~/.bash_profile中配置如下:<br style=\\\"box-sizing:border-box;\\\"/>\\\n<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">export $PATH:$GOROOT/bin</code><br style=\\\"box-sizing:border-box;\\\"/>\\\n如果是windows需要使用<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">;</code>符号分割两个路径, mac和类unix都是用<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">:</code>符号分割</p>\\\n<ol start=\\\"2\\\" style=\\\"box-sizing:border-box;padding:0px;margin:-5px 0px 20px 20px;word-break:break-word;\\\">\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">GOPATH:</li>\\\n</ol>\\\n<ul style=\\\"box-sizing:border-box;padding:0px;margin:-5px 0px 20px 20px;word-break:break-word;\\\">\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">\\\n<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">go install</code>/<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">go get</code>和 go的工具等会用到GOPATH环境变量.</li>\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">GOPATH是作为编译后二进制的存放目的地和import包时的搜索路径 (其实也是你的工作目录, 你可以在src下创建你自己的go源文件, 然后开始工作)。\\\n<ol style=\\\"box-sizing:border-box;padding:0px;margin:-5px 0px 20px 20px;margin-top:15px;word-break:break-word;\\\">\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">GOPATH之下主要包含三个目录: bin、pkg、src</li>\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">bin目录主要存放可执行文件; pkg目录存放编译好的库文件, 主要是*.a文件; src目录下主要存放go的源文件</li>\\\n</ol>\\\n</li>\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">不要把GOPATH设置成go的安装路径,<br style=\\\"box-sizing:border-box;\\\"/>\\\n可以自己在用户目录下面创建一个目录, 如gopath<br style=\\\"box-sizing:border-box;\\\"/>\\\n操作如下:</li>\\\n</ul>\\\n<pre style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;margin:0px 0px 10px;line-height:1.42857;border:1px solid rgb(204, 204, 204);overflow-x:auto;background:rgb(40, 44, 52);display:block;color:rgb(171, 178, 191);margin-bottom:20px;white-space:pre;overflow:auto;font-size:13px;overflow-wrap:normal;border-radius:4px;padding:15px;word-break:break-word;\\\"><code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:inherit;border-radius:0px;border:none;vertical-align:middle;font-size:13px;background-color:transparent;padding:0px;white-space:pre;\\\"><span style=\\\"box-sizing:border-box;color:rgb(230, 192, 123);\\\">cd</span> ~\\\nmkdir gopath\\\n</code></pre>\\\n<p style=\\\"box-sizing:border-box;margin:0px 0px 25px;word-break:break-word;\\\">在~/.bash_profile中添加如下语句:<br style=\\\"box-sizing:border-box;\\\"/>\\\n<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">GOPATH=/Users/username/gopath</code></p>\\\n<ul style=\\\"box-sizing:border-box;padding:0px;margin:-5px 0px 20px 20px;word-break:break-word;\\\">\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">GOPATH可以是一个目录列表, <code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">go get</code>下载的第三方库, 一般都会下载到列表的第一个目录里面</li>\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">需要把GOPATH中的可执行目录也配置到环境变量中, 否则你自行下载的第三方go工具就无法使用了, 操作如下:<br style=\\\"box-sizing:border-box;\\\"/>\\\n在~/bash_profile中配置,</li>\\\n</ul>\\\n<pre style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;margin:0px 0px 10px;line-height:1.42857;border:1px solid rgb(204, 204, 204);overflow-x:auto;background:rgb(40, 44, 52);display:block;color:rgb(171, 178, 191);margin-bottom:20px;white-space:pre;overflow:auto;font-size:13px;overflow-wrap:normal;border-radius:4px;padding:15px;word-break:break-word;\\\"><code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:inherit;border-radius:0px;border:none;vertical-align:middle;font-size:13px;background-color:transparent;padding:0px;white-space:pre;\\\"><span style=\\\"box-sizing:border-box;color:rgb(230, 192, 123);\\\">export</span> <span style=\\\"box-sizing:border-box;color:rgb(209, 154, 102);\\\">$PATH</span>:<span style=\\\"box-sizing:border-box;color:rgb(209, 154, 102);\\\">$GOPATH</span>/bin\\\n</code></pre>\\\n<ul style=\\\"box-sizing:border-box;padding:0px;margin:-5px 0px 20px 20px;word-break:break-word;\\\">\\\n<li style=\\\"box-sizing:border-box;line-height:30px;\\\">创建一个go项目, 并且编译运行:</li>\\\n</ul>\\\n<pre style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;margin:0px 0px 10px;line-height:1.42857;border:1px solid rgb(204, 204, 204);overflow-x:auto;background:rgb(40, 44, 52);display:block;color:rgb(171, 178, 191);margin-bottom:20px;white-space:pre;overflow:auto;font-size:13px;overflow-wrap:normal;border-radius:4px;padding:15px;word-break:break-word;\\\"><code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:inherit;border-radius:0px;border:none;vertical-align:middle;font-size:13px;background-color:transparent;padding:0px;white-space:pre;\\\">mkdir goproject\\\n<span style=\\\"box-sizing:border-box;color:rgb(230, 192, 123);\\\">cd</span> goproject\\\ntouch hello.go\\\n</code></pre>\\\n<p style=\\\"box-sizing:border-box;margin:0px 0px 25px;word-break:break-word;\\\">在hello.go中输入:</p>\\\n<pre style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;margin:0px 0px 10px;line-height:1.42857;border:1px solid rgb(204, 204, 204);overflow-x:auto;background:rgb(40, 44, 52);display:block;color:rgb(171, 178, 191);margin-bottom:20px;white-space:pre;overflow:auto;font-size:13px;overflow-wrap:normal;border-radius:4px;padding:15px;word-break:break-word;\\\"><code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:inherit;border-radius:0px;border:none;vertical-align:middle;font-size:13px;background-color:transparent;padding:0px;white-space:pre;\\\"><span style=\\\"box-sizing:border-box;color:rgb(198, 120, 221);\\\">package</span> main\\\n<span style=\\\"box-sizing:border-box;color:rgb(198, 120, 221);\\\">import</span> <span style=\\\"box-sizing:border-box;color:rgb(152, 195, 121);\\\">&quot;fmt&quot;</span>\\\n<span style=\\\"box-sizing:border-box;\\\">func <span style=\\\"box-sizing:border-box;color:rgb(97, 174, 238);\\\">main</span><span style=\\\"box-sizing:border-box;\\\">()</span> </span>{\\\n      fmt.Println(<span style=\\\"box-sizing:border-box;color:rgb(152, 195, 121);\\\">&quot;Hello, GO !&quot;</span>)\\\n}\\\n</code></pre>\\\n<p style=\\\"box-sizing:border-box;margin:0px 0px 25px;word-break:break-word;\\\">在项目根目录下执行<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">go build</code>命令来构建你的项目, 构建后会生成hello文件<br style=\\\"box-sizing:border-box;\\\"/>\\\n运行生成的文件<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">./hello</code>, terminal中输出: <code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">Hello, GO !</code><br style=\\\"box-sizing:border-box;\\\"/>\\\n当然你也可以直接运行命令<code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">go run hello.go</code>来执行程序.</p>\\\n<p style=\\\"box-sizing:border-box;margin:0px 0px 25px;word-break:break-word;\\\"><em style=\\\"box-sizing:border-box;\\\">如果要上述设置生效, 可以执行命令: <code style=\\\"box-sizing:border-box;font-family:Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace;color:rgb(199, 37, 78);border-radius:4px;border:none;white-space:pre-wrap;vertical-align:middle;font-size:13px;background-color:rgb(246, 246, 246);padding:2px 4px;\\\">source ~/.bash_profile</code>,  上述所有操作均为mac系统下的操作, 如果是非mac系统, 请自行变通.</em></p>\\\n\\\n          </div>\\\n        </div>\\\n    </div></div></div></div></div></div>\\\n</div>\\\n</span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":15624}]"
metadata_diff: {"new":{"id":"c025e3ca810043e5b9693fa9ed1e8bf1","parent_id":"061de1401cfc4cfaadf6e74e015970e9","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764345782554,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T16:20:16.079Z
created_time: 2025-11-28T16:20:16.079Z
type_: 13