Trouble with getting command line "goimports" working.

blov · · 1264 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am brand new to go, coming from mobile app development (android/ios).</p> <p>I have set up a pretty standard go environment, using default path variables and have verified go works with some simple hello world examples.</p> <p>I am learning about goimports now and went to run it, but I got command not found. I ran &#34;go get golang.org/x/tools/cmd/goimports&#34; to get it, which appears to execute correctly, but no matter what I do I keep getting &#34;command not found&#34;.</p> <p>This is probably a total newb question, but I&#39;ve spent over an hour going down rabbit hole after rabbit hole trying to find out what is going wrong here.</p> <hr/>**评论:**<br/><br/>luckyleprechaun98: <pre><p>Add <code>$GOPATH/bin</code> to your path</p></pre>calebisstupid: <pre><p>I should have specified I am working on Mac OS, of which I am not the biggest export on. I believe I have added the path properly; when echo $PATH I get &#34;/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/bin&#34; which indicates that /usr/local/go/bin is added. However, I am still getting the same behavior as mentioned before :-(</p> <p>edit here is my terminal output just now:</p> <pre><code>Calebs-MacBook-Pro:~ calebhamilton$ go get golang.org/x/tools/cmd/goimports Calebs-MacBook-Pro:~ calebhamilton$ goimports -bash: goimports: command not found </code></pre></pre>earthboundkid: <pre><p>What does <code>echo $GOPATH</code> report? I suspect it is unset and your binaries are in $HOME/go/bin. </p></pre>calebisstupid: <pre><p>You are right. It is set to nothing.</p></pre>earthboundkid: <pre><p>Okay. It’s like PATH; you can set it in your bash file. If you set GOBIN, you can specify a separate location for just binaries to be saved to, apart from source files. The default on Mac OS is ~/go/bin. </p></pre>calebisstupid: <pre><p>OK I think I am closer, but still getting command not found. I&#39;m beginning to realize how little I actually know about unix based systems :-(.</p> <p>Here is my terminal output:</p> <pre><code>Calebs-MacBook-Pro:~ calebhamilton$ echo $GOPATH /Users/calebhamilton/go Calebs-MacBook-Pro:~ calebhamilton$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin Calebs-MacBook-Pro:~ calebhamilton$ go get golang.org/x/tools/cmd/goimports Calebs-MacBook-Pro:~ calebhamilton$ goimports -bash: goimports: command not found Calebs-MacBook-Pro:~ calebhamilton$ </code></pre> <p>I attempted to set GOPATH to my go installation, but that throws an error about not setting GOPATH to GOROOT.</p> <p>edit: I&#39;m stupid, it isnt in my $PATH echo. One minute...</p></pre>calebisstupid: <pre><p>OK got it. Thanks for the help!!</p></pre>Frakturfreund: <pre><p>The build executables should be saved in <code>$GOPATH/bin</code>, which you could add to your path. How, depends on your os; on Linux, something like <code>export PATH=$PATH:$GOPATH/bin</code> in your <code>~/.bashrc</code> should work.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1264 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传