I’ve started learning Go
lang. It seems to be built by the right people with the right expectations. So, the first thing I did was install go
on Mac with Homebrew.
JUST A NOTE!
👨💻 I’m teaching thousands of devs how to become VSCode Power Users →
✅ This site is super fast?! It’s hosted with Kinsta on Google servers →
First of all export some paths, and save them in your .zshrc
or .bashrc
files for easy use. Use sudo
if you get error.
# Go development
export GOPATH="${HOME}/.go"
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"
test -d "${GOPATH}" || mkdir "${GOPATH}"
test -d "${GOPATH}/src/github.com" || mkdir -p "${GOPATH}/src/github.com"
Then finally install go, with Homebrew.
brew install go
Also a bunch of dev tools!
go get golang.org/x/tools/cmd/godoc
go get github.com/golang/lint/golint
✅ This site is super fast?! It’s hosted with Kinsta on Google servers →
👨💻 Interested in learning tips/tricks of VSCode, I am launching a course →
VSCode FTW!#
I’m a big fan of VSCode, and have also started making a course on helping you become a Visual Studio Code Power user. So, I’ll be using that for writing/coding with go
.
✅ Install this Go Extension for VSCode →
And we’re done. Let me know if you have any issues.
Peace! ✌
JUST A NOTE!
👨💻 I’m teaching thousands of devs how to become VSCode Power Users →
✅ This site is super fast?! It’s hosted with Kinsta on Google servers →
gman100
Creating a ~/.bashrc file as instructed above didn’t set the environment variables, to fix I created a ~/.bash_profile (I didn’t have one) and added the following to it:
[[ -s ~/.bashrc ]] && source ~/.bashrc
gman100
godoc is bundled with the base Go install but golint isn’t.
Karan Harsh Wardhan
Karans-MacBook-Pro:~ karanharshwardhan$ test –d “${GOPATH}/src/github.com” || mkdir –p “${GOPATH}/src/github.com”
-bash: test: –d: unary operator expected
mkdir: –p: File exists
mkdir: “/Users/karanharshwardhan/.go/src: No such file or directory
Karan H
i get this error when i execute the commands and i don’t really understand how to fix it?
Karans-MacBook-Pro:~ karanharshwardhan$ test –d “${GOPATH}/src/github.com” || mkdir –p “${GOPATH}/src/github.com”
-bash: test: –d: unary operator expected
mkdir: –p: File exists
mkdir: “/Users/karanharshwardhan/.go/src: No such file or directory
Graham Land
Don’t cut and paste from the browser – try typing the commands in as the quotes are not the standard posix character set
gman100
Your command has smart quotes try the following
test –d “${GOPATH}/src/github.com” || mkdir –p “${GOPATH}/src/github.com”
gman100
Wow, my browser added smart quotes (“”) to my last response, you will need normal quotes.
William Grisaitis
Typo with `test-d “${GOPATH}/src/github.com” || mkdir -p “${GOPATH}/src/github.com”` :)
William Grisaitis
(`test-d` -> `test -d`)
Ahmad Awais
Oh, thanks for letting me know. Fixed.
Kokila Alupotha
GOROOT=”$(brew –prefix golang)/libexec”
puting these lines in your .zshrc file will significantly slow down terminal open time.
What I did is get the output of `brew –prefix golang` and put it like this ‘/usr/local/opt/go/libexec’
Ahmad Awais
That makes a lot of sense. Thank you.
Patrick
I’ve heard setting GOROOT is not even necessary.
Rahul Bohra
This command doesn’t work
`go get github.com/golang/lint/golint`
instead this works
`go get golang.org/x/lint/golint`
ERROR Faced :
package github.com/golang/lint/golint: code in directory /Users/USERNAME/go/src/github.com/golang/lint/golint expects import “golang.org/x/lint/golint”
Rahul Bohra
Also, need to know your theme name or if its open source then please share the link, would like to use for mine
Ahmad Awais
Code theme? I built my own called 🦄 Shades of Purple.
Shankar
– Your website is super fast
– Your instructions were super fast
– My installations after following your instructions are super fast
– The Go plugin you recommended is super fast !!!!!!!
Ahmad Awais
Haha. I’m so glad that you found it all useful. :)
Weslley
Why you’d created a hidden folder to $GOPATH variable?
Btw, thank you for homebrew installation support!
Mat Jovanovic
Your golint repo is wrong, I’d switch to golang.org/x/lint/golint
Everything else is awesome, thanks!!!