下载并解压
[root@localhostsoft]# wget -c https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz
将源码包解压后直接放到 /usr/local 目录下, 不用再次 make && make install 来安装了, 开箱即用
[root@localhostsoft]# tar -C /usr/local/ -zxvf go1.8.3.linux-amd64.tar.gz
创建新文件并打开
[root@localhostsoft]# vim /etc/profile.d/go.sh
输入内容 export PATH=$PATH:/usr/local/go/bin
保存退出:wq
立即生效环境变量
[root@localhostsoft]#source/etc/profile.d/go.sh
你可能会说这么添加环境变量, 多不快捷啊!当然你也可以直接在 shell 中输入以下内容:
exportPATH=$PATH:/usr/local/go/bin
1
但就个人认为我这个方法来是比较不错的, 编译一个软件需要添加一个文件,
然后 source 一下导入到当前软件需要添加的环境变量到系统$PATH中, 每一个人都有一个强迫症的习惯吧!
那好, 请尊重自己好了~~~
再在好了, 你可能在shell的任何位置输入 go 命令了!
添加GOPATH和添加环境变量没有本质的区别就是作用不一样罢了
创建一个工作目录, 这个目录就是你以后开发学习 go 语言的主要战场了, 如在用户家目录创建这样一个目录 dev/go
[root@localhost~]# mkdir -p ~/dev/go
创建一个环境变量文件 gopath.sh 并打开
[root@localhost~]# vim /etc/profile.d/gopath.sh
输入GOPATH具体指向位置
exportGOPATH=/root/dev/go
保存退出
:wq!
立即生效这个GOPATH环境变量
[root@localhost~]# source /etc/profile.d/gopath.sh
验证GOPATH环境变量是否添加成功
[root@localhost~]# echo $GOPATH/root/dev/go
OK, 那么这个GOPATH环境变量也就添加完成了
创建测试文件 hello_world.go
[root@localhost~]# vim ~/dev/go/hello_world.go
编辑文件
package main import("fmt")func main(){fmt.Println("Hello world!")}
运算测试文件 hello_world.go
[root@localhost ~]#go run ~/dev/go/hello_world.go Hello world!
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 安装Go运行环境
- 第一章 Go安装与运行
- Ubuntu 12.04上安装HBase并运行
- Ubuntu 12.04上安装 MongoDB并运行
- 安装和运行 .NET Core 版本的 PowerShell
- 用安装在 Docker 中的 jenkins 运行 Docker 任务
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Agile Web Application Development with Yii 1.1 and PHP5
Jeffrey Winesett / Packt Publishing / 2010-08-27
In order to understand the framework in the context of a real-world application, we need to build something that will more closely resemble the types of applications web developers actually have to bu......一起来看看 《Agile Web Application Development with Yii 1.1 and PHP5》 这本书的介绍吧!