Skip to content

Instantly share code, notes, and snippets.

@golife-sysop
Last active August 24, 2018 18:09
Show Gist options
  • Save golife-sysop/6577c27fce41608f51789a339456e080 to your computer and use it in GitHub Desktop.
Save golife-sysop/6577c27fce41608f51789a339456e080 to your computer and use it in GitHub Desktop.
示範在 Linux 從頭開始編譯 go-ethereum,並完成安裝到順利執行起 geth (於 CentOS Linux 7.4)

編譯、安裝 go-ethereum

開始

  • 底下假設 $GOETHEREUMROOT 為您欲安裝的目標主目錄
    • 請自行代換成正確、您所希望的目錄 (e.g., /home/bitcoind 建議是寫絕對路徑 (absolute path) 為妥,比較不會有不小心弄錯的地方)
先下載 Go 並安裝、設定執行環境
  • $ mkdir downloads
  • $ cd $GOETHEREUMROOT/downloads
  • $GOETHEREUMROOT/downloads$ curl -LO https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz
  • $GOETHEREUMROOT/downloads$ shasum -a 256 go1.7*.tar.gz
    • (比對 SHA-256 hash value 確為 702ad90f705365227e902b42d91dd1a40e48ca7f67a2f4b2fd052aaa4295cd95)
  • $GOETHEREUMROOT/downloads$ sudo tar zxvf ./go1.7.linux-amd64.tar.gz -C /usr/local
  • $GOETHEREUMROOT/downloads$ sudo vim /etc/profile.d/path.sh
    • 加上 export PATH=$PATH:/usr/local/go/bin
    • (按 : Ubuntu 的話,則修改 /etc/profile)
  • $GOETHEREUMROOT/downloads$ cd $GOETHEREUMROOT
日後將 Go 的程式與執行檔統一放置
  • $GOETHEREUMROOT$ mkdir -p ~/projects/go/src
  • $GOETHEREUMROOT$ mkdir -p ~/projects/go/bin
  • $GOETHEREUMROOT$ vim ~/.bash_profile
    • 加上

      ...
      export GOBIN="$HOME/projects/go/bin"
      export GOPATH="$HOME/projects/go/src"
      
  • $GOETHEREUMROOT$ source ~/.bash_profile
測試、確認可順利執行
  • $GOETHEREUMROOT$ vim ~/projects/go/src/hello.go

    package main
    
    import "fmt"
    
    func main() {
        fmt.Printf("Hello, World!\n")
    }
    
  • $GOETHEREUMROOT$ go install $GOPATH/hello.go

  • $GOETHEREUMROOT$ $GOBIN/hello

    Hellow, World!

然後就可以開始安裝 Go compiler 囉!!!~

  • $GOETHEREUMROOT$ sudo yum install golang

接下來,透過 Go compiler 來 make go-ethereum

  • $GOETHEREUMROOT$ git clone [email protected]:ethereum/go-ethereum.git go-ethereum/
  • $GOETHEREUMROOT$ cd go-ethereum/
  • $GOETHEREUMROOT$ make geth

好了

  • (真的!!! 😂 別懷疑,這樣就好了,真的可以開始執行 geth 了 😂 Congratulations!!!~ 🎉)
  • $GOETHEREUMROOT$ ./build/bin/geth

Addendum

  • make 完 geht,其實可以把所有 tool 都 make 出來 :
    • $GOETHEREUMROOT$ make all

    • 別忘了參考 go-ethereum 的 README,有條列出每個 tool 的用途,e.g.,

      • $ ./build/bin/rlpdump --hex CE0183FFFFFFC4C304050583616263
      [
        01,
        ffffff,
        [
          [
            04,
            05,
            05,
          ],
        ],
        "abc",
      ]
      

參考資料

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment