安装Go,配置Go环境(实力亲测)

栏目: Go · 发布时间: 6年前

内容简介:版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wd2014610/article/details/80328315

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wd2014610/article/details/80328315

区块链研发

现在区块链项目大多都是用 Go 语言写的,其实语言都是想通的,如果你其他语言学习的好,那么你学习Go语言起来,也是非常简单的,如果你对区块链比较感兴趣,那么来学学Go也是一点问题都没有的。

一、了解一下Go

访问一下Go语言的官网

Go官网

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Go是一门开源的编程语言,它能够让你更快的编译,更加可靠,编程效率更高。

安装Go,配置Go环境(实力亲测)

二、下载Go

点击首页的Download Go进入下载页 下载Go

安装Go,配置Go环境(实力亲测)

选择你的操作系统对应的安装包

三、安装Go

  • 当你点击完第二部,就会开始下载对应的安装包,会打开一个新的安装指导页
    安装指导页面
    安装Go,配置Go环境(实力亲测)
    mac的话,就双击打开刚刚下载的安装包,跟着步骤一步步安装即可。
  • 你的Go就安装在以下位置了
    The package installs the Go distribution to /usr/local/go.
    安装完成后,需要重新打开一个终端
/usr/local/go/bin :watch: 18:13:11
$ ls -l
total 59016
-rwxr-xr-x  1 root  wheel  11199852 Mar 29 12:29 go
-rwxr-xr-x  1 root  wheel  15608476 Mar 29 12:37 godoc
-rwxr-xr-x  1 root  wheel   3403104 Mar 29 12:29 gofmt

/usr/local/go/bin :watch: 18:13:14
$

四、测试一下安装是否成功

  • Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.

    (如果想要测试一下Go是否安装成功,需要在工作空间中编写一个小小的测试)

    Create your workspace directory, $HOME/go. (If you’d like to use a different directory, you will need to set the GOPATH environment variable.)

    (首先来创建一个工作空间,默认是在Home目录下的go目录,那么我现在不想在这个目录,我想重新换一个目录,请参考步骤五)

    Next, make the directory src/hello inside your workspace, and in that directory create a file named hello.go that looks like:

    (创建一个文件夹src/hello,在文件下创建一个名字为hello.go的文件)

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

安装Go,配置Go环境(实力亲测)

  • 编译这个文件
~/Block/go/hello :watch: 18:33:19
$ go build
  • 编译成功后,会生成一个hello的可执行文件
~/Block/go/hello :watch: 18:33:44
$ ls
hello    hello.go

~/Block/go/hello :watch: 18:34:40
$
  • 运行一下这个文件

    输出hello,world就表示Go安装成功了。

~/Block/go/hello :watch: 18:36:04
$ ./hello 
hello, world

~/Block/go/hello :watch: 18:36:08
$
  • 看一下Go的版本号
~/Block/go/hello :watch: 18:37:43
$ go version
go version go1.10.1 darwin/amd64

~/Block/go/hello :watch: 18:37:52
$
  • 清除掉编译后的结果
~/Block/go/hello :watch: 19:42:08
$ go clean

~/Block/go/hello :watch: 19:42:11
$ ls
hello.go

五、更换Go的工作空间位置

5.1 Bash

  • Bash

    Edit your ~/.bash_profile to add the following line:

    如果你用的是Bash配置,编辑Home目录下的.bash_profile文件,在其中添加一行。

    我的$HOME=/Users/wangdong

#go
export GOPATH=$HOME/Block/go
  • 我想将我这个目录当作Go的工作空间
~/Block/go :watch: 18:26:46
$ pwd
/Users/wangdong/Block/go

~/Block/go :watch: 18:26:48
$ 
  • 编辑完成后使配置生效
source ~/.bash_profile

5.2 Zsh

  • 如果你用的是Zsh

    Edit your ~/.zshrc file to add the following line:

export GOPATH=$HOME/go
  • export GOPATH=$HOME/go
export GOPATH=$HOME/go

六、卸载Go

  • 如果你现在不想用Go了,你想要卸载。
    只需要删除你系统中的Go的安装包即可
    This is usually /usr/local/go under Linux, Mac OS X, and FreeBSD or c:\Go under Windows.
    Linux、Mac OS X和FreeBSD在/usr/local/go目录;
    Windows 在c:\Go
  • 配置文件的清理
    进入第五步,清理掉Go的环境配置,将工作空间文件夹清理掉。
    卸载完成。

好啦,下面就可以愉快的开始Go语言的学习啦。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Foundations of PEAR

Foundations of PEAR

Good, Nathan A./ Kent, Allan / Springer-Verlag New York Inc / 2006-11 / $ 50.84

PEAR, the PHP Extension and Application Repository, is a bountiful resource for any PHP developer. Within its confines lie the tools that you need to do your job more quickly and efficiently. You need......一起来看看 《Foundations of PEAR》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具