Go环境安装

https://golangtc.com/download下载


Go环境安装

PC环境:Ubuntu 15.10 64位机

先看张这个月的编程语言排行榜,会发现C下降的特别快,而移动应用和web编程语言都在逐渐上升,其中go上升最明显。所以我决定在学习java、android的同时也准备学go。给自己加油。 
这里写图片描述

Go安装

Go支持三种安装方式:Go源码安装、Go标准包安装、第三方工具安装。 
这里只讲下标准安装。

下载

访问https://golang.org/dl/,或者 https://golangtc.com/download下载,下载go1.6.3.linux-amd64.tar.gz。题外话:如果不是64位系统,强烈建议更换成64位操作系统。

安装

我一般将开发环境安装在根目录下的opt目录。

tar -zxvf go1.6.3.linux-amd64.tar.gz -C /opt/go
  • 1

环境设置

需要设置GOROOT、GOBIN、GOPATH还有PATH。

export GOROOT=/opt/go
export PATH=$PATH:$GOROOT/bin/
export GOPATH=~/goWorkProjects/goPath
export GOBIN=$GOPATH/bin
  • 1
  • 2
  • 3
  • 4

这几个一定要配置,否则有些go命令会因为GOBIN没有配置而不支持。GOPATH允许多个目录,采用分隔符分开(linux是冒号)。这些配置我通常将他们写入~/.bashrc文件,也可以/etc/profile~/.profile。这个看个人 喜好了。 
根据GO的约定,GOPATH【工作目录】需要建立3个目录:

  • bin(存放编译后生成的可执行文件)
  • pkg(存放编译后生成的包文件)
  • src(存放项目源码)

自此,go的环境安装好了,怎么验证呢,打开终端,执行go

jindg@nc:~$ go
Go is a tool for managing Go source code.

Usage:

    go command [arguments]

The commands are:

    build       compile packages and dependencies
    clean       remove object files
    doc         show documentation for package or symbol
    env         print Go environment information
    fix         run go tool fix on packages
    fmt         run gofmt on package sources
    generate    generate Go files by processing source
    get         download and install packages and dependencies
    install     compile and install packages and dependencies
    list        list packages
    run         compile and run Go program
    test        test packages
    tool        run specified go tool
    version     print Go version
    vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

    c           calling between Go and C
    buildmode   description of build modes
    filetype    file types
    gopath      GOPATH environment variable
    environment environment variables
    importpath  import path syntax
    packages    description of package lists
    testflag    description of testing flags
    testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

看到go的Usage信息,就说明go已经安装成功了。如果命令不存在,检查下自己对PATH环境变量或source下刚才设置的环境变量文件。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值