0

自动化脚本实现go安装与升级

 2 years ago
source link: https://cloudsjhan.github.io/2019/01/12/%E8%87%AA%E5%8A%A8%E5%8C%96%E8%84%9A%E6%9C%AC%E5%AE%9E%E7%8E%B0go%E5%AE%89%E8%A3%85%E4%B8%8E%E5%8D%87%E7%BA%A7/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

自动化脚本实现go安装与升级

发表于 2019-01-12

| 分类于 go

| 阅读次数:

| 字数统计: 290

|

阅读时长 ≈ 1

自动化脚本实现go安装与升级

源码安装:

在 home 目录下建立 installGo目录,然后在该目录下新建升级与部署文件以及下载最新的 golang 源码包:

以下是 installOrUpdate.sh 具体内容:

# !/bin/bash

if [ -z "$1" ]; then
​ echo "usage: ./install.sh go-package.tar.gz"
​ exit
fiif [ -d "/usr/local/go" ]; then
​ echo "Uninstalling old go version..."
​ sudo rm -rf /usr/local/go
fi
echo "Installing..."
sudo tar -C /usr/local -xzf $1
echo export GOPATH=/go" >> /etc/profile
echo export GOROOT=/usr/local/go >> /etc/profile
echo export PATH=$PATH:$GOROOT/bin:$GOPATH/bin1 >> /etc/profile
source /etc/profile
rm -rf $1
echo "Done"

然后运行:

sudo sh install.sh go1.10.linux-amd64.tar.gz

  • 或者手动设置好GOPATH,GOROOT

    编辑 /etc/profile 在文件尾部加入:

export GOPATH=/go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin1

运行 source /etc/profile 让环境变量生效

至此,Go 已安装成功

  • 如果需要升级的话只需要将最新的源码包下载到第一步的 installGo 文件夹下,然后运行sudo sh install.sh go1.xx.linux-amd64.tar.gz 即可。

  • shell脚本更新地址github

-------------The End-------------
坚持原创技术分享,您的支持将鼓励我继续创作!
(>给这篇博客打个分吧<)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK