在windows10 Linux (centos7)中安装go golang (够浪) 并测试运行

官方下载安装页面

https://golang.org/doc/install
git主页
https://github.com/golang/go

相关下载地址

https://golang.org/dl/
linux版本 (Linux 2.6.23 or later, Intel 64-bit processor)
https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
windows版本(Windows 7 or later, Intel 64-bit processor)
https://dl.google.com/go/go1.12.5.windows-amd64.msi
源码
https://dl.google.com/go/go1.12.5.src.tar.gz

centos7下载linux版本的

  1. 下载安装包
    wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
  2. 解压
    sudo tar -C /usr/local/ -xzf go1.12.5.linux-amd64.tar.gz
  3. 设置PATH
    管理员身份执行哦
    echo 'export PATH=$PATH:/usr/local/go/bin' >>/etc/bashrc
    [及时生效 可选]
    终端输入:
    export PATH=$PATH:/usr/local/go/bin
    按需
    GOROOT=/usr/local/go
    GOPATH

测试安装是否成功

cd ~/
vim hello.go



package main

import "fmt"

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

代码写好后
执行 go run hello.go 直接运行程序
执行go build hello.go 编译成二进制程序到当前目录

ls -ls


124940 -rw-rw-r--. 1 centos centos 127938445 May  7 01:32 go1.12.5.linux-amd64.tar.gz
  1964 -rwxr-xr-x. 1 root   root     2010039 May 27 06:13 hello
     4 -rw-r--r--. 1 root   root          74 May 27 06:08 hello.go

windows的安装

下载msi安装包

下载地址:
https://dl.google.com/go/go1.12.5.windows-amd64.msi
一路安装下去. 完成.

设置环境变量 (需确认.如果没有就新建)

按组合键 alt+鼠标左键 双击 ->在点击 高级设置 -> 点击 环境变量 -> 在系统环境变量的path中加入 c:Goin

测试安装

新建文件 hello.go 编辑内容为

package main

import "fmt"

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

组合按键 WIN+r ->输入 cmd -> 按 enter

C:Usersmakeit>go run hello.go
hello, world

C:Usersmakeit>go build hello.go

C:Usersmakeit>hello
hello, world

ok.

原文地址:https://www.cnblogs.com/lovesKey/p/10930531.html