Golang development environment configuration under MAC

Source: Internet
Author: User
Tags install brew install go sublime text gocode

The advantages of the go language in development efficiency and operational efficiency have favored many people, so there is a tendency to turn to the development of go language.

The following describes the development environment configuration in Mac OS x Golang.

1. Install Brew

Brew is a package management system developed by Ruby under a Mac, and its official website is http://brew.sh. You just have to do it in your terminal.

" $ (Curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install) "

To complete the installation.

Enter commands after installation

Brew Update

To get updates and switch to the fastest source

2. Install Go

Brew Install Go

3. Installing the Distributed Management tool HG

Brew Install HG

4. Create environment variable folder for Go

CD $HOME

mkdir Go

Vim ~/.bash_profile

Join

Export Gopath= $HOME/go

Export path= $HOME/bin: $GOPATH/bin: $PATH

Save

SOURCE ~/.bash_profile

If you use the default terminal to do so, but my Mac in addition to bash and zsh, usually with zsh, so for bash and zsh can run go need this configuration

Vim ~/.profile

Join

Export Gopath= $HOME/go

Export path= $HOME/bin: $GOPATH/bin: $PATH

Save

Vim ~/.bash_profile

Join

SOURCE ~/.profile

Save

Vim ~/.ZSHRC

Join

SOURCE ~/.profile

Save

In this way, the environment variables for the two terminals are configured to complete

Package Main Import " FMT " Func Main () {FMT. Printf ("Hello,World")}

You can save this code as a test.go file, enter the command go run test.go to test the run

5.gosublime

Believe that more people are willing to use sublime to write code.

If you do not have a package control, you can press CTRL + ' Enter the following code to install

Import Urllib2,os; Pf= ' Package control.sublime-package '; Ipp=sublime.installed_packages_path (); Os.makedirs (IPP) if not os.path.exists (IPP) else None; Urllib2.install_opener (Urllib2.build_opener (urllib2. Proxyhandler ())); Open (Os.path.join (IPP,PF), ' WB '). Write (Urllib2.urlopen (' http://sublime.wbond.net/' +pf.replace (', '%20 '). Read () ); print ' Restart Sublime Text to finish installation '

After restarting Sublime, press Shift+ctrl+p to enter install, and then search Gosublime to mount it

Then install Gocode as the Code hint tool and enter in the terminal

Go get-u github.com/nsf/gocode

Go Install Github.com/nsf/gocode

When we press CTRL+B, we can pop up a console and enter the go build Test.go running a Go code discovery suggests that our environment variables are not configured, because GOSUBLIME environment variables need to be configured separately, and bash and zsh configurations do not work in Gosublime.

Modify the Gosublime configuration: Under the Preferences menu, locate the package Settings, find Gosublime, and then find Settings-default. Re-open the file, change the env to:

" Env " " Gopath ":"$HOME/go","PATH""$HOME/ Bin: $GOPATH/bin: $PATH" },

And for the shell we can also modify, for example, if you want to change zsh, you can change:

" Shell ": [" $zsh"],

At this point, we run the go code to find that the compilation can pass

Golang development environment configuration under MAC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.