Ubuntu 16.04 下简单安装使用golang之备忘
刚开始学习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之备忘的更多相关文章
- Ubuntu 16.04下编译安装Apache2.4和PHP7结合
Ubuntu 16.04下编译安装Apache2.4和PHP7结合,并安装PDOmysql扩展. 1.编译安装apache2.4.20 1 第一步: ./configure --prefix=/usr ...
- Ubuntu 16.04下apt安装ssh及卸载(含FileZilla 使用过程)
前言:文件发布测试过程中需要使用Windows和Ubuntu实现文件共享. 以下内容转载自:http://blog.csdn.net/jiang13479/article/details/535014 ...
- Ubuntu 16.04下vsftpd 安装配置实例
从https://www.linuxidc.com/Linux/2017-06/144807.htm转载 第一步:安装VSFTPD sudo apt-get install vsftpd 安装完成后启 ...
- Ubuntu 16.04下如何安装VMware-Workstation
一.下载 下载地址:https://my.vmware.com/cn/group/vmware/details?downloadGroup=WKST-1411-LX&productId=686 ...
- RabbitMQ在Ubuntu 16.04下的安装与配置
安装执行如下命令: echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d ...
- Ubuntu 16.04下的安装RabbitMQ
安装 添加源 echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/ra ...
- Ubuntu 16.04下FireFox安装Flash插件
下载: https://get.adobe.com/flashplayer/ 选择tar.gz包 解压 sudo tar zxvf flash_player_npapi_linux.x86_64.ta ...
- Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用【转】
本文转载自:http://www.linuxdiyf.com/linux/24086.html Ubuntu 16.04下EasyOpenJTAG+OpenOCD的安装和使用 发布时间:2016-09 ...
- 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 ...
随机推荐
- 功能强大的StickyHeaderListView:标题渐变、吸附悬停、筛选分类、动态头部
StickyHeaderListView 主要是通过 ListView 添加头部实现,将复杂的头部分解为若干部分,如下图:Header 1(广告位).Header 2(频道位).Header 3(运营 ...
- react-ssr
为什么使用SSR 与传统 SPA(Single-Page Application - 单页应用程序)相比 服务器端渲染(SSR)的优势主要在于: 更好的 SEO,由于搜索引擎爬虫抓取工具可以直接查看完 ...
- LeetCode题解之Find the Difference
1.题目描述 2.题目分析 比较两个字符串中加入的一个字符,由于可能在字符串中加入一个已经存在的字符,因此使用hash table 去统计字符个数最好. 3.代码 char findTheDiffer ...
- 优化 ExpressRoute 路由
当你有多个 ExpressRoute 线路时,可以通过多个路径连接到 Azure.结果就是,你所采用的路由可能不是最理想的 - 也就是说,你的流量可能会经历较长的路径才能到达 Azure,而 Azur ...
- pycharm something
e1:使用的版本2016.3 发现无法执行py程序,执行菜单为灰色.选择py为2.7. e2:使用过jython可以运行,但是语法有问题str.formate无法执行
- iOS7中UIView的animateKeyframesWithDuration方法讲解
iOS7中UIView的animateKeyframesWithDuration方法讲解 在iOS7中,给UIView添加了一个方法用来直接使用关键帧动画而不用借助CoreAnimation来实现,那 ...
- Python学习---装饰器/迭代器/生成器的学习【all】
Python学习---装饰器的学习1210 Python学习---生成器的学习1210 Python学习---迭代器学习1210
- 【数据结构】 顺序表查找(折半查找&&差值查找)
#include <stdio.h> #include <stdlib.h> #include <time.h> #define MAXSIZE 10 首先构造一个 ...
- matlab中关于函数句柄、feval函数以及inline函数的解析 (转)
http://blog.sina.com.cn/s/blog_7bff755b010180l3.html MATLAB函数句柄 函数句柄(Function handle)是MATLAB的一种数据类型. ...
- gitlab+jenkins环境搭建.md
gitlab+jenkins自动化部署环境搭建 环境说明 系统 主机 IP 安装软件 CentOS 7 study-1 192.168.100.51 gitlab.git CentOS 7 study ...