访问:https://golang.org/dl/

下载 go1.12.4.linux-amd64.tar.gz

wget https://dl.google.com/go/go1.12.4.linux-amd64.tar.gz

sudo tar -zxvf go1.12.4.linux-amd64.tar.gz -C /opt

检查安装是否成功

cd /opt/go/bin

./go version

go version go1.12.4 linux/amd64

设置环境变量

vi /etc/profile

export GOROOT=/opt/go
export GOPATH=/home/ubuntu/go
export GOPROXY=https://goproxy.io
export GOARCH=amd64
export GOOS=linux
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin source /etc/profile

其中,GOPROXY 可以解决 golang.org/x/... 系列包无法下载的问题。

编写 HelloWorld 文件,测试运行环境。

package main
import "fmt"
func main(){
fmt.Println("hello,world!")
}
go run hello.go
go build hello.go

创建 go.mod 文件

go mod init hello

用 Gin 实现一个简单的 http 服务

import (
"gopkg.in/gin-gonic/gin.v1"
"net/http"
) func main(){ router := gin.Default() router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello World")
})
router.Run(":8000")
}

直接编译执行

go run hello

可以看到引用的包都被自动下载了

go: finding github.com/gin-contrib/sse latest
go: finding github.com/gin-gonic/gin/render latest
go: finding github.com/gin-gonic/gin/binding latest
go: finding github.com/gin-gonic/gin/json latest
go: finding golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
go: downloading golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
go: finding gopkg.in/go-playground/validator.v8 v8.18.2
go: finding github.com/ugorji/go/codec latest
go: finding github.com/golang/protobuf/proto latest
go: finding gopkg.in/yaml.v2 v2.2.2
go: downloading gopkg.in/go-playground/validator.v8 v8.18.2
go: downloading gopkg.in/yaml.v2 v2.2.2
go: finding github.com/ugorji/go v1.1.4
go: finding github.com/golang/protobuf v1.3.1
go: downloading github.com/ugorji/go v1.1.4
go: downloading github.com/golang/protobuf v1.3.1
go: extracting gopkg.in/go-playground/validator.v8 v8.18.2
go: extracting gopkg.in/yaml.v2 v2.2.2
go: extracting github.com/golang/protobuf v1.3.1
go: extracting github.com/ugorji/go v1.1.4
go: extracting golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405

HTTP 服务启动正常,可以通过浏览器访问了。

[GIN-debug] [WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode) [GIN-debug] GET / --> main.main.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8000

ubuntu go 开发环境搭建的更多相关文章

  1. ubuntu java开发环境搭建(jdk+tomcat+eclipse)

    一.jdk的安装配置. 1.下载jdk. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213 ...

  2. 【Ubuntu Java 开发环境搭建 】

    配置环境变量  在终端下:  sudo gedit /etc/profile   这里当然有些熟悉ubuntu的朋友也可以用 vim,   刚从windows转过来的朋友还是用gedit看着舒服写. ...

  3. Windows7+VirtualBox+Ubuntu本地开发环境搭建

    首先下载相应的VirtualBox和Ubuntu镜像文件 安装Ubuntu操作系统 一 网络设置 将虚拟机的network连接模式设置为Bridge模式,注意无线网卡要与本机的无线网卡名称一致 在wi ...

  4. ubuntu scrapy 开发环境搭建

    我的版本是14.04 1.更新系统  ##如果系统没有换国内下载路径需要换下系统的更新下载路径 http://www.cnblogs.com/seablog/p/7043798.html sudo a ...

  5. Ubuntu下开发环境搭建

    安装基础开发包,主要gcc,g++等 sudo apt-get install build-essential 未完待续

  6. 我的开发环境搭建(ubuntu菜鸟)

    前段时间把系统换成了ubuntu,经过一段时间到发展,终于可以比较正常到完成开发工作了,但是就在今天,我的系统崩了,进不了桌面,而且终端里边到中文也显示乱码,尝试了网上说到各种方法无效,最终我决定重装 ...

  7. odoo开发环境搭建(二):安装Ubuntu 17虚拟机

    odoo开发环境搭建(二):安装Ubuntu 17虚拟机 下载镜像文件: 配置网络: 安装vmware tools: 配置共享文件夹: 选中虚拟机,右键编辑设置里边配置共享文件夹,指定windows本 ...

  8. win10子系统linux.ubuntu开发环境搭建

    移步新博客... win10子系统linux.ubuntu开发环境搭建

  9. OK335xS Ubuntu 12.04.1 版本 Android 开发环境搭建

    /******************************************************************************************** * OK33 ...

随机推荐

  1. (一)数据库系统概述和ER图

    1.数据库系统 数据库系统有数据库.数据库管理系统.应用系统和数据库管理员组成.数据库呢就是数据的集合,应用系统和管理员就不说了,数据库管理系统即常说的DBMS,比如我们用的mysql,oracle, ...

  2. top命令参数详解

    简介 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. top显示系统当前的进程和其他状况,是一个动态显示过程,即可以通过用户按 ...

  3. [python](Docker SDK)上传镜像到私有仓库(tls、身份认证)

    (Docker SDK)上传镜像到私有仓库(tls.身份认证) API:https://docker-py.readthedocs.io/en/stable/ 环境:python:3.7.3 配置参数 ...

  4. maven打断点报错

  5. memcpy 与strcpy的区别

      C/C++中mencpy的代码实现:https://www.cnblogs.com/goul/p/10191705.html C/C++中strcpy的代码实现:https://www.cnblo ...

  6. mysql时区配置

    1.修改linux系统时区:ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime 修改为美洲美国洛杉矶时间 2.查看mysql时区 ...

  7. mac使用sublime text3打开当前文件夹的终端

    打开sublime text3,同时按住shift+command+p打开扩展列表, 选择Package Control: Install Pageage,回车. 在输入框输入: terminal,回 ...

  8. AcWing:144. 最长异或值路径(dfs + 01字典树)

    给定一个树,树上的边都具有权值. 树中一条路径的异或长度被定义为路径上所有边的权值的异或和: ⊕ 为异或符号. 给定上述的具有n个节点的树,你能找到异或长度最大的路径吗? 输入格式 第一行包含整数n, ...

  9. python-日常用法小记

    1.判断是否是数字 math.isnan("a") 2.数学math math.log(x) 3.查看安装路径 import sys print sys.path 4.字符串与日期 ...

  10. IDEA如何将写好的java类(UDF函数)打成jar包上传linux

    一.编写一个UDF函数,实现将字符串大写转小写 import org.apache.hadoop.hive.ql.exec.UDF; import org.apache.hadoop.io.Text; ...