區塊鍊研發
現在區塊鍊項目大多都是用Go語言寫的,其實語言都是想通的,如果你其他語言學習的好,那麼你學習Go語言起來,也是非常簡單的,如果你對區塊鍊比較感興趣,那麼來學學Go也是一點問題都沒有的。
一、了解一下Go
通路一下Go語言的官網
Go官網Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Go是一門開源的程式設計語言,它能夠讓你更快的編譯,更加可靠,程式設計效率更高。
二、下載下傳Go
點選首頁的Download Go進入下載下傳頁
下載下傳Go選擇你的作業系統對應的安裝包
三、安裝Go
- 當你點選完第二部,就會開始下載下傳對應的安裝包,會打開一個新的安裝指導頁 安裝指導頁面 mac的話,就輕按兩下打開剛剛下載下傳的安裝包,跟着步驟一步步安裝即可。
-
你的Go就安裝在以下位置了
The package installs the Go distribution to /usr/local/go.
安裝完成後,需要重新打開一個終端
/usr/local/go/bin ⌚ 18:13:11
$ ls -l
total 59016
-rwxr-xr-x 1 root wheel 11199852 Mar 29 12:29 go
-rwxr-xr-x 1 root wheel 15608476 Mar 29 12:37 godoc
-rwxr-xr-x 1 root wheel 3403104 Mar 29 12:29 gofmt
/usr/local/go/bin ⌚ 18:13:14
$
四、測試一下安裝是否成功
-
Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.
(如果想要測試一下Go是否安裝成功,需要在工作空間中編寫一個小小的測試)
Create your workspace directory, $HOME/go. (If you’d like to use a different directory, you will need to set the GOPATH environment variable.)
(首先來建立一個工作空間,預設是在Home目錄下的go目錄,那麼我現在不想在這個目錄,我想重新換一個目錄,請參考步驟五)
Next, make the directory src/hello inside your workspace, and in that directory create a file named hello.go that looks like:
(建立一個檔案夾src/hello,在檔案下建立一個名字為hello.go的檔案)
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
- 編譯這個檔案
~/Block/go/hello ⌚ 18:33:19
$ go build
- 編譯成功後,會生成一個hello的可執行檔案
~/Block/go/hello ⌚ 18:33:44
$ ls
hello hello.go
~/Block/go/hello ⌚ 18:34:40
$
-
運作一下這個檔案
輸出hello,world就表示Go安裝成功了。
~/Block/go/hello ⌚ 18:36:04
$ ./hello
hello, world
~/Block/go/hello ⌚ 18:36:08
$
- 看一下Go的版本号
~/Block/go/hello ⌚ 18:37:43
$ go version
go version go1.10.1 darwin/amd64
~/Block/go/hello ⌚ 18:37:52
$
- 清除掉編譯後的結果
~/Block/go/hello ⌚ 19:42:08
$ go clean
~/Block/go/hello ⌚ 19:42:11
$ ls
hello.go
五、更換Go的工作空間位置
5.1 Bash
-
Bash
Edit your ~/.bash_profile to add the following line:
如果你用的是Bash配置,編輯Home目錄下的.bash_profile檔案,在其中添加一行。
我的$HOME=/Users/wangdong
#go
export GOPATH=$HOME/Block/go
- 我想将我這個目錄當作Go的工作空間
~/Block/go ⌚ 18:26:46
$ pwd
/Users/wangdong/Block/go
~/Block/go ⌚ 18:26:48
$
- 編輯完成後使配置生效
source ~/.bash_profile
5.2 Zsh
-
如果你用的是Zsh
Edit your ~/.zshrc file to add the following line:
export GOPATH=$HOME/go
- export GOPATH=$HOME/go
export GOPATH=$HOME/go
六、解除安裝Go
-
如果你現在不想用Go了,你想要解除安裝。
隻需要删除你系統中的Go的安裝包即可
This is usually /usr/local/go under Linux, Mac OS X, and FreeBSD or c:\Go under Windows.
Linux、Mac OS X和FreeBSD在/usr/local/go目錄;
Windows 在c:\Go
-
配置檔案的清理
進入第五步,清理掉Go的環境配置,将工作空間檔案夾清理掉。
解除安裝完成。
好啦,下面就可以愉快的開始Go語言的學習啦。