Mac下搭建go语言开发环境

笔者使用的是mac系统,因此介绍mac下golang的环境搭建。

1、安装Golang的SDK

google官网被墙下载地址如下: http://www.golangtc.com/download ,下载最新的安装包,之后双击安装即可。

安装完成之后,打开终端,输入go、或者go version(查看安装版本)出现如下信息即表示安装成功:

LCore:~ lcore$ go version
go version go1.4.1 darwin/amd64
LCore:~ lcore$

2、配置环境变量

安装完sdk之后接下来便是配置环境变量了,打开终端输入cd ~ 进入用户主目录,之后输入ls -all命令查看是否存在.bash_profile

文件,存在既使用vim .bash_profile打开并编辑该文件。根据自己实际情况,内容如下:

export GOPATH=/Users/lcore/dev/code/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

GOPATH:日常开发的根目录。GOBIN:是GOPATH下的bin目录。

且需要gobin目录加入到path路径下,生成的可执行文件就可以直接运行了。

退出vim,使用source ~/.bash_profile即可完成对golang环境变量的配置了,可以在终端中输入go env查看配置后的效果:

LCore:~ lcore$ go env
GOARCH=”amd64″
GOBIN=”/Users/lcore/dev/code/go/bin”
GOCHAR=”6″
GOEXE=””
GOHOSTARCH=”amd64″
GOHOSTOS=”darwin”
GOOS=”darwin”
GOPATH=”/Users/lcore/dev/code/go”
GORACE=””
GOROOT=”/usr/local/go”
GOTOOLDIR=”/usr/local/go/pkg/tool/darwin_amd64″
CC=”clang”
GOGCCFLAGS=”-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common”
CXX=”clang++”
CGO_ENABLED=”1″

3、开发工具配置(sublime text)

这里笔者选用的是sublime text安装gosublime插件进行开发(golang语法高亮提示),安装方式这里就不多提了。

4、Hello GO

配置好开发环境之后,简单的进行一下go语言的开发。在你的gopath下的src目录下,新建一个文件夹(以项目名称命名),然后在sublime中打开该文件夹,新建main.go文件即可以进行编码了。

package main

import (
“fmt”
)

func main() {
fmt.Println(“hello go”);
}

代码编写完成之后,使用command+b打开sublime text终端,使用go build xx(项目名称)对其进行编译,编译通过后将会显示hello go信息。

《Mac下搭建go语言开发环境》上的0个想法

  1. Casinacho Casino Review. Casinacho Casino Review: A Look Inside the Popular Online Gaming Platform Casinacho Casino is a well-known online gaming platform that has gained popularity among players around the world. With its wide range of games, attractive bonuses, and user-friendly interface, Casinacho Casino casi-casinacho.ca has become a favorite destination for many online gamblers. One of the key features of Casinacho Casino is its impressive selection of games. From classic table games like blackjack and roulette to popular slot machines and video poker, Casinacho Casino offers something for every type of player. The platform is constantly updated with new games, ensuring that players always have something fresh and exciting to try. In addition to its diverse game selection, Casinacho Casino also offers generous bonuses and promotions to its players. New players can take advantage of a welcome bonus that includes free spins and bonus cash, while existing players can benefit from regular promotions and loyalty rewards. These bonuses give players extra value for their money and help to enhance their gaming experience. Casinacho Casino is also known for its user-friendly interface, which makes it easy for players to navigate the platform and find their favorite games quickly. The website is well-designed and intuitive, with clear instructions and helpful tips to guide players through the gaming process. This user-friendly approach has helped Casinacho Casino attract a loyal following of players who appreciate its simplicity and ease of use. Another key advantage of Casinacho Casino is its strong focus on customer service. The platform has a dedicated support team that is available 24/7 to assist players with any questions or concerns they may have. Whether players need help with making a deposit, withdrawing their winnings, or resolving a technical issue, the support team at Casinacho Casino is always ready to help. Overall, Casinacho Casino is a top-rated online gaming platform that offers a high-quality gaming experience to players of all levels. With its wide range of games, attractive bonuses, user-friendly interface, and excellent customer service, Casinacho Casino has established itself as a leader in the online gaming industry. Whether you’re a seasoned player or just starting out, Casinacho Casino has something to offer you. So why not give it a try and see for yourself why so many players love this popular online casino?

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据