1.0 查看是否存在bash_profile
cd ~/.bash_profile
2.0 如果不存在則創建bash_profile Mac環境配置文件
touch ~/.bash_profile
3.0 打開bash_profile
open -t ~/.bash_profile
4.0 添加go 環境變量:(等於號后面的為你的項目存儲目錄)
GOPATH=website/apple/apps
5.0 warning:如果因為創建bash_profile 使命令行ls命令失效而造成go語言無法安裝請關注
5.1 如上打開bash_profile 並加入環境變量
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
5.2 重啟命令行工具 刪除 bash_profile 關閉命令行 刪除 go 文件重新安裝在(/usr/local/)下
rm ~/.bash_profile
5.3 安上文配置方法重新配置即可
6 配置好項目目錄后需要添加三個文件夾
$GOPATH 目錄約定有三個子目錄:
- src 存放源代碼(比如:.go .c .h .s等)
- pkg 編譯后生成的文件(比如:.a)
- bin 編譯后生成的可執行文件(為了方便,可以把此目錄加入到 $PATH 變量中,如果有多個gopath,那么使用
${GOPATH//://bin:}/bin添加所有的bin目錄)
