CentOS 7.5下Go编译环境的搭建

(一)几个比较重要的参考网址:

https://tecadmin.net/install-go-on-centos/

这个是一个比较完整的安装过程说明

https://golang.org/dl/

官网说明,一定权威啦!

本次下载的源码版本为1.12.7,下载地址:

https://golang.org/doc/install?download=go1.12.7.linux-amd64.tar.gz

(二)开始记录

1、利用yum直接进行安装

yum install golang

用yum install golang时出现提示:没有可用软件包 golang,Google一下发现是yum源中没有该软件包,但可以用epel-release(https://blog.csdn.net/upshi/article/details/78987509),简单明了,直接安装epel-release:

yum install epel-release

epel-release安装成功后可以直接用yum进行安装:

yum install golang

现在应该可直接成功了,安装成功后用go version查看其版本为"go version go1.11.5 linux/amd64"到官网一看发现最新版本是1.12.7,心里感觉有点不爽,就想着把yum安装的结果卸载再重新安装。查了下卸载方法(https://golang.org/doc/install?download=go1.12.7.linux-amd64.tar.gz#uninstall):大概意思就是先直接删除go目录,再删除相应的环境变量:

“To remove an existing Go installation from your system delete the go directory. This is usually /usr/local/go under Linux, macOS, and FreeBSD or c:\Go under Windows.

You should also remove the Go bin directory from your PATH environment variable. Under Linux and FreeBSD you should edit /etc/profile or $HOME/.profile. If you installed Go with the macOS package then you should remove the /etc/paths.d/go file. Windows users should read the section about setting environment variables under Windows.”

这里我直接使用的是yum remove golang,再直接删除相应环境变量。
2、利用源码进行安装:
2.1下载源码
go1.12.7.linux-amd64.tar.gz
2.2对源码包进行解压,目标目标为/usr/local
tar -C /usr/local -zxf /mnt/go1.12.7.linux-amd64.tar.gz

2.3设置环境变量GOROOT, GOPATHPATH

Now you need to set up Go language environment variables for your project. Commonly you need to set 3 environment variables as GOROOT, GOPATH and PATH.

GOROOT is the location where Go package is installed on your system.

export GOROOT=/usr/local/go

GOPATH is the location of your work directory. For example my project directory is ~/Projects/Proj1 .

export GOPATH=$HOME/Projects/Proj1

Now set the PATH variable to access go binary system wide.

export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

All the above environment will be set for your current session only. To make it permanent add above commands in ~/.bash_profile file.

这里利用的是直接编辑.bash_profile文件,进行编辑后大概如下所示:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/Projects/GoProject
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

由于设置环境变量后需要再次登录才有效,可以使用如下命令强制刷新:

source ~/.bash_profile.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值