golang學習筆記一(go語言環境搭建)

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Go環境搭建

1 下載安裝包
go語言的官方下載地址是:官方網站 ,如果打不開,可以使用這個地址:鏡像網站。因為我是linux系統,所以選擇go1.9.linux-amd64.tar.gz

2 我安裝的目錄是/usr/local/go,所以使用命令 tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz,這個一般需要root身份或者sudo許可權,解包之後,/usr/local/就會有一個go目錄,go目錄下應該是有bin,src,doc等目錄。

3 配置環境變數,要是想要機器上的所有使用者都生效,那麼需要在/etc/profile中配置,如果只要目前使用者生效,那麼就只需要在~/.profile檔案中配置下邊兩行即可

  • export GOROOT=/usr/local/go
    export PATH=$PATH:$GOROOT/bin

如果是針對所有使用者生效,那麼需要重啟機器,如果只對目前使用者生效,那麼執行 source ~/.profile即可

4 開啟終端,輸入 go version驗證是否安裝成功

~go version   ~go version go1.9 linux/amd64

編輯 hello.go

package mainimport "fmt"func main(){            fmt.Printf("hello,world\n")}

執行

go run hello.go  hello,world

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.