婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > linux中用shell快速安裝配置Go語言的開發環境

linux中用shell快速安裝配置Go語言的開發環境

熱門標簽:騰訊外呼系統價格 電梯外呼訪客系統 浙江人工智能外呼管理系統 百度地圖標注搜索關鍵詞 成都呼叫中心外呼系統平臺 最短的地圖標注 ?兓? 谷歌便利店地圖標注 電銷機器人可以補救房產中介嗎

介紹

go1.5+版本提供編譯好的安裝包,我們只需要解壓到相應的目錄,并添加一些環境變量的配置即可。

Go語言的安裝步驟

     下載安裝包go1.7.linux-amd64.tar.gz

     解壓文件到指定目錄: tar -zxf go1.7.linux-amd64.tar.gz

     設置環境變量:GOROOT, GOPATH, PATH

既然我們可以列出這些步驟,那么便可以將整個過程自動化。

下面是安裝腳本

#!/bin/bash
#Upgrade go version to 1.7
#wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz go1.7.tar.gz

function info() {
 echo -e "\033[1;34m$1 \033[0m"
}

function warn() {
 echo -e "\033[0;33m$1 \033[0m"
}

function error() {
 echo -e "\033[0;31m$1 \033[0m"
}

function usage() {
 info "Upgrade or install golang..."
 info "USAGE:"
 info " ./upgrade.sh tar_file gopath"
 info " tar_file specify where is the tar file of go binary file"
 info " gopath specify where is the go workspace, include src, bin, pkg folder"
}

function createGoPath() {
 if [ ! -d $1 ];
 then
 mkdir -p $1
 fi
 if [ ! -d "$1/src" ];
 then
 mkdir "$1/src"
 fi
 if [ ! -d "$1/bin" ];
 then
 mkdir "$1/bin"
 fi
 if [ ! -d "$1/pkg" ];
 then
 mkdir "$1/pkg"
 fi
}

if [ -z $1 ];
then
 usage
 exit 1
fi

file=$1
if [ ! -f $file ];
then
 error "${file} not exist..."
 exit 1
fi

unzipPath="`pwd`/tmp_unzip_path/"
info $unzipPath

if [ ! -d $unzipPath ];
then
 info "not exist"
 mkdir $unzipPath
fi

tar -zxf $file -C $unzipPath

goroot=$GOROOT
if [ ! -n $GOROOT ];
then
 warn "Use default go root /usr/local/go"
 goroot="/usr/local/go"
fi

gopath=$2
info "Create go workspace, include src,bin,pkg folder..."
if [ -z $2 ];
 then
 user=`whoami`
 gopath="/home/$user/workspace/golang"
 warn "Use $gopath as golang workspace..."
 if [ ! -d $gopath ];
 then
 mkdir -p $gopath
 fi
fi

createGoPath $gopath

info "Copy go unzip files to $goroot"
sudo cp -r "$unzipPath/go" $goroot
rm -rf $unzipPath

#etcProfile="/home/user/Desktop/etc"

etcProfile="/etc/profile"
exportGoroot="export GOROOT=$goroot"
if [ ! -z $GOROOT ];
then
 cat $etcProfile | sed 's/^export.GOROOT.*//' | sudo tee $etcProfile > /dev/null
fi
echo $exportGoroot | sudo tee -a $etcProfile

exportGopath="export GOROOT=$gopath"
if [ ! -z $GOPATH ];
then
 cat $etcProfile | sed 's/^export.GOPATH.*//' | sudo tee $etcProfile > /dev/null
fi
echo "export GOPATH=$gopath" | sudo tee -a $etcProfile

echo 'export PATH=$GOROOT/bin:$GOPATH/bin:$PATH' | sudo tee -a $etcProfile

# ## Replace multiple empty lines with one empty line
cat $etcProfile -s | sudo tee $etcProfile > /dev/null

info "To make configuration take effect, will reboot, pls enter[y/n]"
read -p "[y/n]" isReboot
if [ $isReboot = "y" ];
then
 sudo reboot
fi

講一講腳本做的事情吧

     1、腳本要求輸入編譯好的安裝包,這里本來是可以做成直接下載的, 但是考慮到大多數人是無法連接到golang的官網的,因此放棄了這一步。

     2、解壓文件到指定的目錄, 默認為/usr/local/go , 也可以通過運行時指定

     3、在GOPATH下面創建3個文件夾: src, bin, pkg, GOPATH可以運行時指定,默認為/home/{user}/workspace/golang

     4、設置環境變量: $GOPATH, $GOROOT

     5、重啟服務,使對/etc/profile的修改生效

這里有一些主意的點是,有可能系統配置過golang的環境變量, 那么需要先刪除這些配置,然后重新寫入。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。

您可能感興趣的文章:
  • Ubuntu下安裝Go語言開發環境及編輯器的相關配置
  • 在Mac OS上安裝Go語言編譯器的方法
  • 在Linux系統中安裝Go語言的詳細教程
  • Ubuntu安裝Go語言運行環境
  • Windows下使用go語言寫程序安裝配置實例
  • Go語言運行環境安裝詳細教程
  • GO語言運行環境下載、安裝、配置圖文教程

標簽:邢臺 七臺河 眉山 雅安 紹興 上海 盤錦 宜昌

巨人網絡通訊聲明:本文標題《linux中用shell快速安裝配置Go語言的開發環境》,本文關鍵詞  linux,中用,shell,快速,安裝,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《linux中用shell快速安裝配置Go語言的開發環境》相關的同類信息!
  • 本頁收集關于linux中用shell快速安裝配置Go語言的開發環境的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 墨玉县| 收藏| 广宗县| 五河县| 高安市| 孝义市| 泰兴市| 延津县| 绩溪县| 贵港市| 五华县| 禄劝| 六安市| 北流市| 诏安县| 汾阳市| 泸溪县| 汾阳市| 石门县| 万山特区| 阿拉善左旗| 浦东新区| 聂拉木县| 库车县| 米林县| 绵竹市| 双鸭山市| 兴山县| 兴安县| 边坝县| 民县| 确山县| 土默特左旗| 抚州市| 长沙县| 阿巴嘎旗| 土默特右旗| 萝北县| 玉林市| 清新县| 抚远县|