zoukankan      html  css  js  c++  java
  • Ubuntu 16.04 安装Go 1.9.2

    下载:

    官网下载 https://www.golangtc.com/download,选择 Ubuntu 64版本(linux-amd64),我这里下载的是:go1.9.2.linux-amd64.tar.gz

    安装:

     #解压至系统目录 (注意权限)
    sudo tar -zxvf go1.9.2.linux-amd64.tar.gz -C /usr/local
     #验证

    /usr/local/go/bin/go version

    设置环境变量

    #当前用户
    /etc/profile
    #系统用户
    ~/.bashrc

    这里选择当前用户:

    vim ~/.bashrc
    
    export GOPATH=$HOME/code/golang/ #工作路径
    export GOROOT=/usr/local/go  #设置为go安装的路径
    export GOARCH=386
    export GOOS=linux
    export GOBIN=$GOROOT/bin/ #安装可执行文件路径
    export GOTOOLS=$GOROOT/pkg/tool/
    export PATH=$PATH:$GOBIN:$GOTOOLS

    source ~/.bashrc

    验证

    验证全局变量生效
    go env 查看全局变量的设置
    go version
    验证hello.go
    package main
    import ("bufio"
            "os"
            "fmt"
          )
    func main() {
        fmt.Println("hello world")
        //声明并初始化带缓冲的读取器,从标准输入读取
        inputReader := bufio.NewReader(os.Stdin)
        fmt.Println("Please input your name:")
        //以
    为分隔符读取内容
        input,err := inputReader.ReadString('
    ')
        if err != nil {
            fmt.Printf("Found an error :%s
    ",err)
        }else {
            //对input进行切片操作,去除最后一个换行符
            input = input [:len(input)-1]
            fmt.Printf("hello,%s!
    ",input)
        }
    }

    运行

    pp@pp:~/code/golang$ go run hello.go
    hello world
    Please input your name:
    wsq
    hello,wsq!
    pp@pp:~/code/golang$ go build hello.go
    pp@pp:~/code/golang$ ./hello 
    hello world
    Please input your name:
    wsq
    hello,wsq!
    

      

    问题:

    网上的办法是将 

    export GOBIN=$GOROOT/bin/ #安装可执行文件路径

    直接注释掉,我这里暂时不适用go install命令吧。

  • 相关阅读:
    使用navicat连接mysql报10038错时解决方法
    项目部署之前后端软件部署
    F12调试模式下使用console自动提交
    selenium+python安装配置
    常用dos命令
    jmeter的使用---web测试
    jmeter的安装
    使用JMeter创建数据库(Mysql)测试
    oracle定制定时执行任务
    AWS之Rekognition检测image-text
  • 原文地址:https://www.cnblogs.com/shuqingstudy/p/10023559.html
Copyright © 2011-2022 走看看