Skip to content

Instantly share code, notes, and snippets.

@JethroLee
Forked from golife-sysop/install_go_ethereum.md
Created August 21, 2018 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JethroLee/7a44cb8b5a72583767079be89f664694 to your computer and use it in GitHub Desktop.
Save JethroLee/7a44cb8b5a72583767079be89f664694 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
  • $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/bin"
      export GOPATH="$HOME/projects/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 並 install

  • $GOETHEREUMROOT$ git clone git@github.com:ethereum/go-ethereum.git go-ethereum/
  • $GOETHEREUMROOT$ cd go-ethereum/
  • $GOETHEREUMROOT$ make geth

好了

  • (真的!!! 😂 別懷疑,這樣就好了,真的可以開始執行 geth 了 😂 Congratulations!!!~ 🎉)
  • $GOETHEREUMROOT$ ./build/bin/geth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment