golang 安装脚本

#!/bin/bash env

sudo yum -y install wget curl


echo "download golang ..."
# 获取最新的golangurl
url=`curl https://golang.google.cn/dl/ | grep -i -o -E 'href=".+?linux-amd64.tar.gz"' | head -n 1| egrep -i -o -E 'http[^"]+'`
wget $url

echo "解压glang安装包..."
name=`echo $url | egrep -i -o -E '[^/]+linux-amd64.tar.gz'`
echo "开始启动... "
sudo mv $name /usr/local
cd /usr/local
sudo tar zvxf $name

echo "配置golang 的环境变量..."

cd ~/

sed -i '$a\GOPATH=~/workspace/go' ~/.bash_profile
sed -i '$a\GOROOT=/usr/local/go'  ~/.bash_profile
sed -i '$a\PATH=$PATH:$GOROOT/bin:$GOPATH/bin'  ~/.bash_profile
sed -i '$a\export GOPATH' ~/.bash_profile
sed -i '$a\export PATH' ~/.bash_profile
source ~/.bash_profile

echo "创建GOPATH目录"
mkdir -p ~/workspace/go
cd $GOPATH

mkdir src bin pkg


source ~/.bash_profile

猜你喜欢

转载自www.cnblogs.com/lurenq/p/11987157.html