Skip to content

add go.md #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ You can also follow my [weibo](http://weibo.com/pubyun) for the latest news.
* [OS X的备份和恢复](https://github.com/pubyun/macdev/blob/master/recovery.md)
* [基本设置](https://github.com/pubyun/macdev/blob/master/basic.md)
* [python开发环境的设置](https://github.com/pubyun/macdev/blob/master/python.md)
* [Golang开发环境配置](https://github.com/pubyun/macdev/blob/master/go.md)
* ruby开发环境的设置 - 整理中...
* [Java开发环境的设置](https://github.com/pubyun/macdev/blob/master/java.md)
* [PHP开发环境的设置](https://github.com/pubyun/macdev/blob/master/php.md)
Expand Down
86 changes: 86 additions & 0 deletions go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Golang开发环境配置

以Golang1.8为例

## 包下载

```
# 官方源
curl https://storage.googleapis.com/golang/go1.8.darwin-amd64.tar.gz -o golang.tar.gz
```

### 也可以使用pkg包安装

## 解压

```
tar -zxvf go1.8.darwin-amd64.tar.gz -o golang.tar.gz
```

## 安装到指定位置

```
sudo mkdir -p /opt/local/go/
sudo mv go/ /opt/local/go/
```

## 配置环境变量

```
# vim ~/.bash_profile
# 如果不是用的自带的terminal,就不是这个名字。比例zsh是在~/.zshrc
# 添加以下内容

export GOROOT="/opt/local/go"
export GOBIN="$GOROOT/bin"
export PATH="$PATH:$GOROOT/bin"
export GOPATH="$HOME/code/go/external:$HOME/code/go/projectXX"
```

```
source ~/.bash_profile
```

## 检查是否生效

```
go env
```

以上命令输出为:

```
GOARCH="amd64"
GOBIN="/opt/local/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ooops/code/go/external:/Users/ooops/code/go/me"
GORACE=""
GOROOT="/opt/local/go"
GOTOOLDIR="/opt/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dh/gf2msm053lqcvqwvy7g62sjh0000gn/T/go-build015052219=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
```

写个hello world吧

```
package main

import "fmt"

func main(){
fmt.Println("hello world")
}
```