|
| 1 | +Getting Started with Golang - Windows |
| 2 | +===================================== |
| 3 | + |
| 4 | +Install Go |
| 5 | +---------- |
| 6 | + |
| 7 | +Go to: |
| 8 | + |
| 9 | +* http://golang.org/dl/ |
| 10 | + |
| 11 | +and download and install the .MSI package WITH ALL DEFAULT. Just hit |
| 12 | +NEXT. |
| 13 | + |
| 14 | +* If a previous version was already installed, go to "Add / Remove |
| 15 | + Programs", and remove it beforehand. |
| 16 | + |
| 17 | +The GOPATH is where all your Go code will live. |
| 18 | + |
| 19 | +Create new folder in C:\ named "GoPath" |
| 20 | + |
| 21 | +Go to the "System" control panel, click the "Advanced" tab. Select |
| 22 | +"Environment Variables" and under "System variables": |
| 23 | + |
| 24 | + * add GOPATH variable, set it to "C:\GoPath" |
| 25 | + * add GO15VENDOREXPERIMENT, set it to "1" |
| 26 | + |
| 27 | + |
| 28 | +Install Git |
| 29 | +----------- |
| 30 | + |
| 31 | +Go to: |
| 32 | + |
| 33 | +* http://git-scm.com/downloads |
| 34 | + |
| 35 | +Download and install: |
| 36 | + |
| 37 | +* BUT HEY! when asked to select how to "Adjust your PATH environment", |
| 38 | + select the SECOND choice which is "Use Git from the Windows Command |
| 39 | + Prompt". |
| 40 | + |
| 41 | +* Continue on with the defaults. |
| 42 | + |
| 43 | +Open a NEW terminal (with new env vars), paste this in to install |
| 44 | +those sweet tools: |
| 45 | + |
| 46 | + go get -u -ldflags -H=windowsgui github.com/nsf/gocode/... |
| 47 | + go get -u github.com/abourget/godef/... |
| 48 | + go get -u golang.org/x/tools/cmd/... |
| 49 | + |
| 50 | + |
| 51 | +Install Atom |
| 52 | +------------ |
| 53 | + |
| 54 | +Atom has the best support for coding in Go, has excellent plugins and |
| 55 | +works across platforms. Throw Sublime Text away and use Atom. |
| 56 | + |
| 57 | +Go to: |
| 58 | + |
| 59 | +* https://atom.io/ |
| 60 | + |
| 61 | +Download and install (it will open), and once in there: |
| 62 | + |
| 63 | + * In the Welcome Guide |
| 64 | + |
| 65 | + * Click "Install package" |
| 66 | + |
| 67 | + * Click "Open Installer" |
| 68 | + |
| 69 | + * Search "go-plus" (by joefitzgerald) |
| 70 | + |
| 71 | + * Install it |
| 72 | + |
| 73 | + |
| 74 | +Setup `Git` and `bash` properly |
| 75 | +------------------------------- |
| 76 | + |
| 77 | +Right click on the desktop, and select "Git Bash Here" |
| 78 | + |
| 79 | +Run |
| 80 | + |
| 81 | + atom ~/.profile |
| 82 | + |
| 83 | +This opens Atom. Tweak `~/.profile` to look like these, and *save* the file: |
| 84 | + |
| 85 | + export GOPATH=/c/GoPath |
| 86 | + export PATH=/c/GoPath/bin:$PATH |
| 87 | + eval $(ssh-agent) |
| 88 | + ssh-add $HOME/.ssh/id_rsa |
| 89 | + |
| 90 | +Back to `Git Bash` terminal, run: |
| 91 | + |
| 92 | + atom ~/.gitconfig |
| 93 | + |
| 94 | +Edit the `~/.gitconfig` file to make sure similar lines are in there: |
| 95 | + |
| 96 | + [user] |
| 97 | + name = Your Name |
| 98 | + |
| 99 | + |
| 100 | +Save the files, and exit. |
| 101 | + |
| 102 | + |
| 103 | +Setup GitHub authentication |
| 104 | +--------------------------- |
| 105 | + |
| 106 | + |
| 107 | +### Generate a new key |
| 108 | + |
| 109 | +Run: |
| 110 | + |
| 111 | + cat $HOME/.ssh/id_rsa.pub |
| 112 | + |
| 113 | +If you see `No such file or directory`, continue on, otherwise skip |
| 114 | +this `ssh-keygen` step and go to `Register your key on GitHub`. |
| 115 | + |
| 116 | +Still in "Git Bash", run: |
| 117 | + |
| 118 | + ssh-keygen |
| 119 | + |
| 120 | +Accept the default file name (hit ENTER). This key gives access to |
| 121 | +all your github repos. Secure it with a password when asked. |
| 122 | + |
| 123 | + * This password never leaves your computer, the key shouldn't |
| 124 | + either, but if lost, it is encrypted with this password. |
| 125 | + |
| 126 | + |
| 127 | +### Register your key on GitHub |
| 128 | + |
| 129 | +Run: |
| 130 | + |
| 131 | + cat $HOME/.ssh/id_rsa.pub |
| 132 | + |
| 133 | +Go to: |
| 134 | + |
| 135 | +* https://github.com/settings/ssh |
| 136 | + |
| 137 | +Click "Add SSH key" (at the top right of the box). |
| 138 | + |
| 139 | +Copy the `ssh-rsa .......` in the `Key` input field. Don't fill in |
| 140 | +`Title` (it will use the key comment). |
| 141 | + |
| 142 | +GitHub will ask you to confirm with your GitHub password. |
| 143 | + |
| 144 | + |
| 145 | +Check out your first project, get ready to run and build |
| 146 | +-------------------------------------------------------- |
| 147 | + |
| 148 | +Open "Git Gui" (right click on the Desktop, or run `git gui` in Git |
| 149 | +bash) |
| 150 | + |
| 151 | +Select `Clone Existing Repository`, punch in: |
| 152 | + |
| 153 | +* Source location: `[email protected]:abourget/getting-started-with-golang` |
| 154 | +* Target directory: `C:\GoPath\src\github.com\abourget\getting-started-with-golang` |
| 155 | + |
| 156 | +Go to Atom, select "File" -> "Add Project Folder", and navigate to |
| 157 | +`C:\GoPath\src\github.com\abourget\getting-started-with-golang`. |
| 158 | + |
| 159 | +In `Git Bash`, run: |
| 160 | + |
| 161 | + cd /c/GoPath/src/github.com/abourget/getting-started-with-golang |
| 162 | + go install -v |
| 163 | + getting-started-with-golang |
| 164 | + |
| 165 | +Modify `main.go` in this repository and rerun `go install -v` to compile and |
| 166 | +`getting-started-with-golang` to re-execute the program. |
0 commit comments