刚开始学习Go语言,这里记录下我在Ubuntu 16.04下安装使用golang的过程,方便以后查询。

一、安装

1、添加源

  如果使用默认的源安装golang的话,版本太低,只到1.6,所以要添加一个新的源并更新,执行以下命令:

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update

2、安装

sudo apt install golang-go

  安装之后,可以通过go version命令查看版本。通过新的源安装下来,golang的版本是1.11.4(2019年1月25日)。

3、配置环境

  接下来,还需要做一点配置,我编写在~/.bashrc文件中,内容如下:

export GOPATH=/mydata/golang
export GOBIN=$GOPATH/bin
export PATH=$PATH:${GOPATH//://bin:}/bin

  GOROOT是Go的正式软件所在路径,在我们安装时系统已经自动设置好,所以不用在这里指明。GOPATH是我们自己的软件和第三方的Go软件所在路径,由自己指定,以后安装的各种附属工具会被安装在这里。

二、emacs中的golang支持配置

1、在自己设定的emacs插件目录中下载go-mode插件

  我习惯把emacs的插件目录放在目录:~/.emacs.d/plugins/。进入插件目录,执行以下克隆命令:

git clone https://github.com/dominikh/go-mode.el.git

2、编辑配置文件~/.emacs

  在.emacs文件中添加以下内容:

;; ---------------------golang---------------------
(add-to-list 'load-path "~/.emacs.d/plugins/go-mode.el")
(require 'go-mode)

  保存、退出,再进入编辑Go程序文件,就会有语法高亮、自动格式等功能。

三、代码格式

  Go的工具中提供了gofmt命令来格式化源代码文件,其命令参数如下:

usage: gofmt [flags] [path ...]
  -cpuprofile string
        write cpu profile to this file
  -d    display diffs instead of rewriting files
  -e    report all errors (not just the first 10 on different lines)
  -l    list files whose formatting differs from gofmt's
  -r string
        rewrite rule (e.g., 'a[b:len(a)] -> a[b:]')
  -s    simplify code
  -w    write result to (source) file instead of stdout

  如果是在emacs下编辑,并且已经安装上一步所提到的插件,那么格式会自动设置好。这个风格我不怎么喜欢,先用着吧。

Ubuntu 16.04 下简单安装使用golang之备忘的更多相关文章

  1. Ubuntu 16.04下编译安装Apache2.4和PHP7结合

    Ubuntu 16.04下编译安装Apache2.4和PHP7结合,并安装PDOmysql扩展. 1.编译安装apache2.4.20 1 第一步: ./configure --prefix=/usr ...

  2. Ubuntu 16.04下apt安装ssh及卸载(含FileZilla 使用过程)

    前言:文件发布测试过程中需要使用Windows和Ubuntu实现文件共享. 以下内容转载自:http://blog.csdn.net/jiang13479/article/details/535014 ...

  3. Ubuntu 16.04下vsftpd 安装配置实例

    从https://www.linuxidc.com/Linux/2017-06/144807.htm转载 第一步:安装VSFTPD sudo apt-get install vsftpd 安装完成后启 ...

  4. Ubuntu 16.04下如何安装VMware-Workstation

    一.下载 下载地址:https://my.vmware.com/cn/group/vmware/details?downloadGroup=WKST-1411-LX&productId=686 ...

  5. RabbitMQ在Ubuntu 16.04下的安装与配置

    安装执行如下命令: echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d ...

  6. Ubuntu 16.04下的安装RabbitMQ

    安装 添加源 echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/ra ...

  7. Ubuntu 16.04下FireFox安装Flash插件

    下载: https://get.adobe.com/flashplayer/ 选择tar.gz包 解压 sudo tar zxvf flash_player_npapi_linux.x86_64.ta ...

  8. Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用【转】

    本文转载自:http://www.linuxdiyf.com/linux/24086.html Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用 发布时间:2016-09 ...

  9. Ubuntu 16.04下安装MacBuntu 16.04 TP 变身Mac OS X主题风格

    Ubuntu 16.04下安装MacBuntu 16.04 TP 变身Mac OS X主题风格 sudo add-apt-repository ppa:noobslab/macbuntu sudo a ...

随机推荐

  1. [EXCEL] 不能清除剪贴板: We couldn't free up space on the clipboard. Another program might be using it right now

    Excel复制粘贴时出现以下错误,原因是有程序占用了剪切板. We couldn't free up space on the clipboard. Another program might be ...

  2. 委托学习总结(二)匿名方法和lambda表达式

    之前总结了委托这个困惑着大多初学者的概念,继续来学习匿名方法和lambda表达式 (1)我们之前写了这样一段代码 //自定义一个委托 public delegate int Expression(in ...

  3. java.lang.verifyerror:bad type on orerand stack

    问题: junit测试的时候报这个错:java.lang.verifyerror:bad type on orerand stack 原因:(多种,自行逐个排查) 1.class not find 引 ...

  4. 禁用休眠(删除休眠文件) 关掉此选项可节省C盘好几G空间:文章内容bat文件源码

    @ECHO offTITLE 关掉休眠 MACHENIKE set TempFile_Name=%SystemRoot%\System32\BatTestUACin_SysRt%Random%.bat ...

  5. 长距离单历元非差GNSS网络RTK理论与方法总结(未完)

    2018-11-04 1.状态空间: 状态空间是控制工程中的一个名词.状态是指在系统中可决定系统状态.最小数目变量的有序集合.   而所谓状态空间则是指该系统全部可能状态的集合.简单来说,状态空间可以 ...

  6. You may experience an access violation when you access an STL object through a pointer or reference in a different DLL or EXE

    Symptoms When accessing an STL object created in one DLL or EXE through a pointer or reference in a ...

  7. YBB.DBUtils用法

    通用数据访问类库,兼容ADO.ADO.NET方式访问. 利用ProviderFactory工厂方法,支持Oracle(不需要安装客户端).SQL Server.OleDb和ODBC等数据库访问. ht ...

  8. codeforces 1007B Pave the Parallelepiped

    codeforces 1007B Pave the Parallelepiped 题意 题解 代码 #include<bits/stdc++.h> using namespace std; ...

  9. 基于easyui开发Web版Activiti流程定制器详解(三)——页面结构(上)

    上一篇介绍了定制器相关的文件,这篇我们来看看整个定制器的界面部分,了解了页面结构有助于更好的理解定制器的实现,那么现在开始吧! 首先,我们来看看整体的结构: 整体结构比较简单,主要包括三个部分: 1. ...

  10. python第十八课——常用内置函数

    常用内置函数:round(): print(round(3.14),round(3.99)) print(round(3145.926,-2),round(413.575,2)) abs(): pri ...