教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 Go编程基础之一 Go开发环境搭建

Go编程基础之一 Go开发环境搭建

发布时间:2022-01-14   编辑:jiaochengji.com
教程集为您提供Go编程基础之一 Go开发环境搭建等资源,欢迎您收藏本站,我们将为您提供最新的Go编程基础之一 Go开发环境搭建资源

学习路径:无闻的《Go编程基础》

<h3 id="mac安装golang">Mac安装golang</h3>

官方介绍两种安装方法,同时也可以通过brew安装。

<h4 id="pkg安装">pkg安装</h4>

下载地址
一路下一步即可安装

<h4 id="tar包解压安装">tar包解压安装</h4>

下载地址

<pre class="prettyprint"><code class=" hljs lasso">tar <span class="hljs-attribute">-C</span> /usr/<span class="hljs-built_in">local</span> <span class="hljs-attribute">-xzf</span> go<span class="hljs-variable">$VERSION.</span><span class="hljs-variable">$OS</span><span class="hljs-subst">-</span><span class="hljs-variable">$ARCH.tar.gz</span></code></pre>

解压即可安装

<h4 id="brew安装">brew安装</h4>

教程

<pre class="prettyprint"><code class=" hljs cmake">brew <span class="hljs-keyword">install</span> go</code></pre> <h3 id="path设置">PATH设置</h3>

以brew安装go为例。

<pre class="prettyprint"><code class=" hljs bash"><span class="hljs-keyword">export</span> PATH=<span class="hljs-variable">$PATH</span>:/usr/local/opt/go/libexec/bin <span class="hljs-keyword">export</span> GOROOT=/usr/local/opt/go/libexec <span class="hljs-keyword">export</span> GOPATH=<span class="hljs-variable">$HOME</span>/.go <span class="hljs-keyword">export</span> PATH=<span class="hljs-variable">$PATH</span>:<span class="hljs-variable">$GOROOT</span>/bin:<span class="hljs-variable">$GOPATH</span>/bin</code></pre>

前以上加入.zshrc,source ~/.zshrc使之生效
注:export PATH=$PATH:/usr/local/opt/go/libexec/bin不设置也是可以的,因为/usr/local/bin中有对应的链接。

<h3 id="测试">测试</h3> <h4 id="新建文件">新建文件</h4> <pre class="prettyprint"><code class=" hljs avrasm">vim hello<span class="hljs-preprocessor">.go</span></code></pre> <h4 id="输入代码">输入代码</h4> <pre class="prettyprint"><code class=" hljs go"><span class="hljs-keyword">package</span> main <span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span> <span class="hljs-keyword">func</span> main(){ fmt.Printf(<span class="hljs-string">"Hello, go!"</span>) }</code></pre> <h4 id="测试运行">测试运行</h4> <pre class="prettyprint"><code class=" hljs go"><span class="hljs-keyword">go</span> run hello.<span class="hljs-keyword">go</span></code></pre> <h4 id="输出结果">输出结果</h4> <pre class="prettyprint"><code class=" hljs erlang-repl"><span class="hljs-variable">Hello</span>, <span class="hljs-function_or_atom">go</span><span class="hljs-exclamation_mark">!</span><span class="hljs-comment">%</span></code></pre>
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css"/>
到此这篇关于“Go编程基础之一 Go开发环境搭建”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
想系统学习GO语言(Golang
Go编程基础—windows下Go语言开发环境搭建
从零开始学习GO语言-搭建Go语言开发环境-快速开发入门第一个小程序
GO语言零基础从入门到精通视频教程
Go编程基础之一 Go开发环境搭建
Hyperledger Fabric2.2环境搭建(一)——go语言
初识GO语言以及GO语言安装及环境搭建
查看go 安装了哪些包_go语言基础入门(一)
golang基础教程
Go Golang Beego微服务基础实战视频教程

[关闭]
~ ~