This is a creation in Article, where the information may have evolved or changed.
Install Go
- Can go to Golang China to download the go installation package
- Unpacking the installation package
tar -C /usr/local -xzf <安装包>
- Add environment variables ' export path= $PATH:/usr/local/go/bin to/etc/profile (full system installation) or. BASHRC (bash) or. ZSHRC (in zsh)
- Perform
source .zshrc
update changes
If you want to install to a specified location
- Change the second step to
/usr/local
what you want, for example$HOME/go
- Add environment Variables
export GOROOT=$HOME/go
andexport PATH=$PATH:$GOROOT/bin
Setting up the Go workspace
The go code must be placed in the working space. It is actually a directory that contains three subdirectories:
- The SRC directory contains the go source files, which are organized into packages (each directory corresponds to a package)
- Pkg Directory contains Package objects
- The bin directory contains executable commands
Add a workspace to an environment variableexport GOPATH=$HOME/gowork
Add the Bin directory to the environment variableexport PATH=$PATH:$GOPATH/bin
End of Go installation
Use
You write the source file of go to the SRC directory in the workspace
If you have a GitHub account, it should be github.com/user_name
used as your source path, so it will be convenient to upload to GitHub, even if not upload, anyway, the source can be placed in the SRC directory anywhere
Configure sublime text as a development tool for go
Just install gosublime
, then Preferences > package setting > gosublime > user setting
add the following in:
{ "env": { "GOPATH": "$HOME/go_work", "GOROOT": "/usr/local/go" }}