Go环境搭建

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

内容简介:2018-10-27笔记注:对我来说,

2018-10-27笔记

  1. Go源码下载
$ wget https://dl.google.com/go/go1.11.1.linux-amd64.tar.gz
  1. 解压到指定文件夹
$ sudo tar -zxf  go1.11.1.linux-amd64.tar.gz -C /usr/local
  1. 配置环境,在~/.bashrc最后添加以下命令
export GOROOT=/usr/local/go #go安装目录
export GOPATH=~/GO/         #go项目路径
export PATH=$PATH:$GOROOT/bin/:$GOPATH/bin

注: GOPATH 主要有三个文件: src 放置项目源码,一般一个项目一个目录,比方说 src/projA 放置 projA 的项目源码, src/projB 放置 projB 的项目源码; bin 放置可执行文件; pkg 编译后生成的文件。

  1. 重启终端,测试Go,输入
$ go version

go get问题

对我来说, go get 不知道为什么,就是各种 time out ,尝试了很多方法还是一样。这里说一下, go get 实际上做了什么事情,首先他通过 git 将源码下载到 $GOPATH/src 中,然后执行 go install 来编译源码,输出可执行文件到 $GOPATH/bin 中,所以 go get 失败的可以尝试去把源码下载下来,然后手动 go install

举个例子,安装 maxbrunsfeld/counterfeiter ,这个在搭建 fabric 的时候会用到:看 README.md 的安装说明:

go get -u github.com/maxbrunsfeld/counterfeiter ,然后执行以下命令,

$ mkdir -p $GOPATH/src/github.com/maxbrunsfeld
$ cd $GOPATH/src/github.com/maxbrunsfeld
$ git clone https://github.com/maxbrunsfeld/counterfeiter.git
$ go install ./counterfeiter

golang/tools

这个也是搭建 fabric 会用到

$ mkdir -p $GOPATH/src/golang.org/x/
$ cd $GOPATH/src/golang.org/x/
$ git clone https://github.com/golang/tools.git

这个不需要 go install


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

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

Modeling the Internet and the Web

Modeling the Internet and the Web

Pierre Baldi、Paolo Frasconi、Padhraic Smyth / Wiley / 2003-7-7 / USD 115.00

Modeling the Internet and the Web covers the most important aspects of modeling the Web using a modern mathematical and probabilistic treatment. It focuses on the information and application layers, a......一起来看看 《Modeling the Internet and the Web》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具