1、下载mac需要安装的文件包,点击pkg,一直下一步安装即可完成。
https://golang.org/doc/install?download=go1.12.6.darwin-amd64.pkg
软件包将被安装到 /usr/local/go
检查安装包是否安装成功
neusoftdeMacBook-Pro:go neusoft$ go version
go version go1.12.6 darwin/amd64
2、配置环境变量
1、打开终端,进入用户主目录
cd ~
2、输入ls -all命令查看是否存在.bash_profile;
neusoftdeMacBook-Pro:~ neusoft$ ls -all
total 43240
drwxr-xr-x+ 38 neusoft staff 1216 6 18 21:02 .
drwxr-xr-x 5 root admin 160 1 1 11:02 ..
-r-------- 1 neusoft staff 9 5 16 2018 .CFUserTextEncoding
-rw-r--r--@ 1 neusoft staff 14340 4 29 20:12 .DS_Store
drwx------ 12 neusoft staff 384 6 18 21:00 .Trash
drwxr-xr-x 2 neusoft staff 64 7 5 2018 .android
-rw------- 1 neusoft staff 5741 6 18 20:57 .bash_history
-rw-r--r-- 1 neusoft staff 0 8 15 2018 .bash_profile
drwx------ 7 neusoft staff 224 6 18 21:01 .bash_sessions
drwx------ 3 neusoft staff 96 5 18 2018 .config
drwxr-xr-x 3 neusoft staff 96 8 17 2018 .m2
-rw------- 1 neusoft staff 13 12 20 21:05 .mysql_history
drwxr-xr-x 3 neusoft staff 96 5 18 2018 .node-gyp
drwxr-xr-x 7 neusoft staff 224 5 18 2018 .npm
drwxr-xr-x 28 neusoft staff 896 5 24 2018 .npminstall_tarball
drwxr-xr-x 4 neusoft staff 128 7 24 2018 .oracle_jre_usage
-rw------- 1 neusoft staff 12 6 27 2018 .python_history
drwx------ 3 neusoft staff 96 6 26 2018 .ssh
drwxr-xr-x 6 neusoft staff 192 5 31 2018 .subversion
-rw------- 1 neusoft staff 9198 12 20 20:07 .viminfo
drwxr-xr-x 3 neusoft staff 96 5 18 2018 .vscode
drwxr-xr-x 3 neusoft staff 96 5 18 2018 .weex-templates
drwxr-xr-x 7 neusoft staff 224 5 24 2018 .weex_tmp
drwxr-xr-x 5 neusoft staff 160 5 18 2018 .xtoolkit
drwx------@ 4 neusoft staff 128 6 12 2018 Applications
drwx------+ 5 neusoft staff 160 4 12 07:45 Desktop
drwx------+ 5 neusoft staff 160 6 18 20:54 Documents
drwx------+ 13 neusoft staff 416 6 18 21:00 Downloads
drwx------@ 65 neusoft staff 2080 1 31 21:59 Library
drwx------+ 3 neusoft staff 96 5 16 2018 Movies
drwx------+ 4 neusoft staff 128 11 27 2018 Music
drwx------+ 3 neusoft staff 96 11 27 2018 Pictures
drwxr-xr-x+ 4 neusoft staff 128 5 16 2018 Public
drwxr-xr-x 3 neusoft staff 96 12 20 21:02 PycharmProjects
-rw-r--r-- 1 root staff 21495613 10 26 2018 finalshell_data.zip
-rwxr-xr-x 1 neusoft staff 3530 10 26 2018 finalshell_install.sh
drwxr-xr-x 2 neusoft staff 64 2 20 22:01 tools
drwxr-xr-x 8 neusoft staff 256 12 11 2018 workspace
3、存在既使用vim .bash_profile打开文件;
vim .bash_profile
4、输入下面代码,
其中
-
GOPATH: 日常开发的根目录。
-
GOBIN:是GOPATH下的bin目录。
使用方法一安装,可配置
export GOPATH=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
5、执行source,让配置生效
source ~/.bash_profile
6、检查环境变量是否配置成功
go env
neusoftdeMacBook-Pro:testdata neusoft$ go env
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/Users/neusoft/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/usr/local/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z6/l24gc64j0jqf3rb23y732v640000gn/T/go-build639467550=/tmp/go-build -gno-record-gcc-switches -fno-common"
到此go语言安装成功,并且环境变量也配置成功,可以写简单的hello.go验证一下。
6、安装goland开发工具,下载地址:https://www.jetbrains.com/go/
7、安装完成后怎么激活?