golangインストールスクリプト

1108 ワード

#!/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