开发环境
操作系统:Fedora-Workstation-x86_64-27-1.6
Go版本:1.9.2
下载安装包:https://golang.org/dl/
选择Linux的tar包go1.9.2.linux-amd64.tar.gz
#注意:安在go包需要能访问google先!
wget https://dl.google.com/go/go1.9.2.linux-amd64.tar.gz
tar -zxvf go1.9.2.linux-amd64.tar.gz
cp -rf ./go /usr/local
cd /usr/local/go/bin
./go version
配置环境变量
vim /etc/profile
1 2 3 |
export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin |
source /etc/profile
go的基本命令:
查看单个函数的帮助文档:
godoc fmt Println
构建本地go帮助网页(如果操作系统不能访问国外网络,此操作可能会失败):
godoc -http=:8120
配置vim
以下配置参考文章:
https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.4.md
http://blog.csdn.net/xxy0403/article/details/53909252
https://www.cnblogs.com/yuuyuu/p/5222980.html
如果配置不成功可能是网络原因或者vim版本不对。
mkdir -p ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vi /root/.vimrc
1 2 3 4 5 6 7 8 9 10 11 12 13 |
set nocompatible filetype off set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'gmarik/Vundle.vim' Plugin 'fatih/vim-go' call vundle#end() filetype plugin indent on set nu set cursorline set ruler syntax on Plugin 'Valloric/YouCompleteMe' |
然后在vim内执行命令(时间比较久):先输入PluginInstall然后,GoInstallBinaries
创建开发目录
mkdir -p ~/go/src
mkdir -p ~/go/pkg
mkdir -p ~/go/bin
cd ~/go/src
1 2 3 4 5 6 7 8 |
vim helloWorld.go package main import( “fmt” ) func main(){ fmt.Println(“Hello World!”) } |
go run hello.go
学习资源
https://golang.org/doc/
https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/preface.md
https://github.com/astaxie/go-best-practice/blob/master/ebook/zh/preface.md
https://github.com/Unknwon/go-fundamental-programming
本文作者: GavinDong
版权属于: GavinDong博客
文章链接: https://gavindong.com/2038.html
如果使用过程中遇到问题,可 **点击此处** 交流沟通。
版权所有,转载时必须以链接形式注明作者和原始出处及本声明。
评论列表(1条)
在线手册:http://www.shouce.ren/api/view/a/5581