Golang安装和环境配置

栏目: Go · 发布时间: 6年前

内容简介:下载安装包,国内地址:添加环境变量,修改/etc/profile 或$HOME/.profile或/etc/profile.d/目录的文件查看golang版本:

安装golang:

下载安装包,国内地址: https://golang.google.cn/dl/

$ sudo tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz  //解压

添加环境变量,修改/etc/profile 或$HOME/.profile或/etc/profile.d/目录的文件

$ sudo vi /etc/profile.d/brianconfig.sh  //添加以下内容
export GOROOT=/usr/local/go //定义GOROOT
export PATH=$PATH:/usr/local/go/bin // 添加go/bin到系统环境变量PATH中
export GOPATH=/work/wks_golang //添加GOPATH变量

查看golang版本:

$ go version
go version go1.12.5 linux/amd64

查看GOROOT

$ go env GOROOT
/usr/local/go

查看GOPATH

$ echo $GOPATH
/
/work/wks_golang

demo测试

在/work/wks_golang目录内,新建 src/hello , 创建 hello.go :

package main
import "fmt"
func main() {
    fmt.Printf("hello, world\n")
}

使用go tool构建:

$ cd ./src/hello
$ go build

The command above will build an executable named hello in the directory alongside your source code. Execute it to see the greeting:

$ ./hello

hello, world

让ZSH支持自动补全

查看oh-my-zsh中是否有golang插件

$ ls ~/.oh-my-zsh/plugins/golang/
$ vi ~/.zshrc

修改 ~/.zshrc ,找到plugins数组添加:

plugins=(... golang)

官网设置GOPATH指南

GOPATHgo 1.8后默认是 $HOME/go ,也可以根据情况设定。

场景1 - Bash

修改 ~/.bash_profile ,添加

export GOROOT=$HOME/go
export GOPATH=$HOME/go

启用使之生效

source ~/.bash_profile

场景2 - Zsh

修改 ~/.zshrc 添加:

export GOPATH=$HOME/go

启用使之生效

source ~/.zshrc

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Rapid Web Applications with TurboGears

Rapid Web Applications with TurboGears

Mark Ramm、Kevin Dangoor、Gigi Sayfan / Prentice Hall PTR / 2006-11-07 / USD 44.99

"Dear PHP, It's over between us. You can keep the kitchen sink, but I want my MVC. With TurboGears, I was able to shed the most heinous FileMaker Pro legacy 'solu-tion' imaginable. It has relationshi......一起来看看 《Rapid Web Applications with TurboGears》 这本书的介绍吧!

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具