markdown 如何使用Atom和所有的铃声和口哨在MacOS上安装功能性Go开发环境。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 如何使用Atom和所有的铃声和口哨在MacOS上安装功能性Go开发环境。相关的知识,希望对你有一定的参考价值。
# Installing a Go development environment on Mac OS for Beginners
## Installing _Go_
First, install the _Go_ compiler from _Google's Go_ Website:
https://golang.org/dl/
Or just use this link to download the 1.8 version for Mac OS:
https://storage.googleapis.com/golang/go1.8.darwin-amd64.pkg
Unless you have a good reason, you should probably avoid using
package managers like _brew_, _macports_ and _fink_ to install Go.
### _How to Test_
You should now be able to call this command and get the _Go_ help text as an output:
``` bash
/usr/local/go/bin/go
```
The output should be something like:
``` markdown
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
(etc)
```
## Choose a GOPATH
This is a folder where all _Go_ project will be placed and managed, if you dont know what to choose, you can use `~/golang`.
```bash
mkdir ~/golang
```
Now remember the full path to this folder, you will need it later. You can get it this way:
```bash
cd ~/golang
pwd
```
You will probably obtain something like:
``` bash
/Users/cdemers/golang
```
### _How to Test_
Doing the following should not return an error:
``` bash
cd ~/golang
```
## Create a setenv.sh file
Move in your previously created `GOPATH` folder and create a file named `setenv.sh`, this file will contain the following except that the `GOPATH` variable must match your own `GOPATH`:
``` bash
# (Notice that there is no #!/bin/bash here)
export GOPATH=`cd ~/golang && pwd`
export GOROOT=/usr/local/go
export PATH=$PATH:$GOPATH/bin
```
You don't need to set this file as executable, you will _source_ it, not execute it.
### _How to Test_
Doing the following should not return an error:
``` bash
source ~/golang/setenv.sh
```
And afterward, doing the following:
``` bash
echo $GOPATH
```
Should return something like:
``` bash
/Users/cdemers/golang
```
And also, you should now be able to call this command and get the same _Go_ help text as an output as before:
``` bash
$GOROOT/bin/go
```
The output should be something like:
``` markdown
Go is a tool for managing Go source code.
(etc)
```
## Installing the Base Go Tools
Now you are ready to install some very useful _Go_ tools, after sourcing the _setenv.sh_ file, run the following four commands:
``` bash
go get -u github.com/nsf/gocode
go get -u golang.org/x/tools/cmd/cover
go get -u github.com/alecthomas/gometalinter
go get -u github.com/zmb3/gogetdoc
go get -u github.com/tools/godep
gometalinter --install --update
```
or, if `$GOPATH/bin` is not in your path:
```
$GOPATH/bin/gometalinter --install --update
```
If the previous steps were successful, these commands should work without any problems. You should now have a bunch of new command line tools located in `$GOPATH/bin` (which in our case should translate to something like `/Users/cdemers/golang/bin`).
### _How to Test_
The following should return the `gocode` file, and not return an error:
``` bash
ls $GOPATH/bin/gocode
```
The following should return the `cover` file, and not return an error:
``` bash
ls $GOPATH/bin/cover
```
The following should return the `golint` file, and not return an error:
``` bash
ls $GOPATH/bin/golint
```
If the previous tests were successful, the installation of these tools should be ok. However, if you want to be very thorough, you can validate that the `$GOPATH/bin` folder contains at least all the following files:
``` bash
aligncheck deadcode errcheck goconst goimports gometalinter gotype interfacer staticcheck unconvert cover dupl gocode gocyclo golint gosimple ineffassign lll structcheck varcheck
```
# The _Atom_ IDE
Now, you are ready to install the _Atom_ IDE, which, as of now is the most suited for _Go_ development. This will likely change in the future, but for now, if you want a good support for _Go_ in a nice IDE environment, you have to go for _Atom_.
The first step is to install the Atom IDE, which is opensource and free.
You can download it from the home page of: https://atom.io
This will provide you with a zip file, you only have to unzip it and move the resulting Mac OS application to your `/Applications` folder.
Next, enable the Atom command line tools by starting Atom, then clicking on the **Atom** menu in the top menu bar, then click on **Install Shell Commands**, and then you are ready to move on.
### _How to Test_
To test that the _Atom_ command line is working, simply execute the `atom` command in a terminal:
``` bash
atom
```
As a result, _Atom_ should start.
To test that the _apm_ command line is working, simply execute the `apm` command in a terminal (you need to have started Atom at least once before, so that it will install the `apm` cli):
```bash
apm
```
As a result, you should have the help text of the `apm` command line, which look like this:
``` markdown
apm - Atom Package Manager powered by https://atom.io
Usage: apm <command>
(etc)
```
# Install the _Atom_ extensions for _Go_
To enable all the _Go_ capabilities of _Atom_, you have to install a couple of extensions. This is the last step and is quick and easy. In a terminal and execute the following command:
``` bash
apm install go-plus go-config go-rename environment file-icons highlight-selected minimap minimap-highlight-selected monokai
```
The CLI should give you confirmation that all went well, and you are now ready to _Go_.
One last thing, for your environment to work properly, you must start _Atom_ using the command line from a terminal, and you must have _sourced_ the `setenv.sh` file first:
``` bash
source ~/golang/setenv.sh
```
And then you are all set, start _Atom_ from the same terminal:
``` bash
atom
```
And start building wonderful things!
以上是关于markdown 如何使用Atom和所有的铃声和口哨在MacOS上安装功能性Go开发环境。的主要内容,如果未能解决你的问题,请参考以下文章