Mac環境 go語言之入門HelloWorld

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

1. 安裝mercurial

Mercurial 是一種輕量級分布式版本控制系統,採用 Python 語言實現

可以輸入hg命令查詢系統是否安裝mercurial,可以如下兩種命令安裝

$sudo pip install mercurial


安裝成功之後

$sudo easy-install mercurial


安裝之後,輸入hg命令,如下內容顯示,表示成功安裝 mercuria

$ hg

Mercurial Distributed SCM


basic commands:


 add           add the specified files on the next commit

 annotate      show changeset information by line for each file

 clone         make a copy of an existing repository

 commit        commit the specified files or all outstanding changes

 diff          diff repository (or selected files)

 export        dump the header and diffs for one or more changesets

 forget        forget the specified files on the next commit

 init          create a new repository in the given directory

 log           show revision history of entire repository or files

 merge         merge working directory with another revision

 pull          pull changes from the specified source

 push          push changes to the specified destination

 remove        remove the specified files on the next commit

 serve         start stand-alone webserver

 status        show changed files in the working directory

 summary       summarize working directory state

 update        update working directory (or switch revisions)


use "hg help" for the full list of commands or "hg -v" for details

如上命令安裝失敗,可以直接去下載安裝

2. 擷取go原始碼

$hg clone -r release https://go.googlecode.com/hg/ go

warning: go.googlecode.com certificate with fingerprint 3f:8a:ae:12:fc:c2:65:d0:64:42:ee:6f:cc:b3:41:a1:9a:76:6e:8c not verified (check hostfingerprints or web.cacerts config setting)

adding changesets

adding manifests

adding file changes

added 19559 changesets with 68116 changes to 8835 files

updating to branch release-branch.go1.3

4167 files updated, 0 files merged, 0 files removed, 0 files unresolved

會在當前路徑建立go目錄

3.安裝go

進入 go源碼(go/src)目錄進行安裝,執行如下命令

$ ./all.bash

最後會顯示出如下內容


ALL TESTS PASSED


---

Installed Go for darwin/amd64 in /Users/angel/iProject/go

Installed commands in /Users/angel/iProject/go/bin

*** You need to add /Users/angel/iProject/go/bin to your PATH.

4.編寫HelloWorld

$ cat helloworld.go 

package main


import (

    "fmt"

)



func main(){

    fmt.Println("Hello World")

}

5.運行程式

$ go run helloworld.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.