Ahmad Awais

NAVIGATE


SHARE


Install Go Lang on MacOS with Homebrew!

Ahmad AwaisAhmad Awais

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 โ†’

Go

Founder & CEO at Langbase.com ยท Ex VP DevRel Rapid ยท Google Developers Advisory Board (gDAB) founding member. ๐Ÿง‘โ€๐Ÿ’ป AI/ML/DevTools Angel Investor โฏ AI/ML Advisory Board member San Francisco, DevNetwork

๐ŸŽฉ Award-winning Open Source Engineer & Dev Advocate ๐ŸฆŠ Google Developers Expert Web DevRel ๐Ÿš€ NASA Mars Ingenuity Helicopter mission code contributor ๐Ÿ† 8th GitHub Stars Award recipient with 3x GitHub Stars Award (Listed as GitHub's #1 JavaScript trending developer).

๐ŸŒณ Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator. ๐Ÿ“Ÿ Teaching thousands of developers Node.js CLI Automation (100 videos ยท 22 Projects) & VSCode.pro course. Over 142 Million views, 22 yrs Blogging, 56K developers learning, 200+ FOSS.

โœŒ๏ธ Author of various open-source dev-tools and software libraries utilized by millions of developers worldwide โ“ฆ WordPress Core Developer ๐Ÿ“ฃ TEDx Speaker with 100+ international talks.

โœจ As quoted by: Satya Nadella ยท CEO of Microsoft โ€” Awais is an awesome example for developers.
๐Ÿ™Œ Leading developers and publishing technical content for over a decade ๐Ÿ’œ Loves his wife (Maedah) โฏ Read more about Ahmad Awais.

๐Ÿ‘‹โ€ฆ Awais is mostly active on Twitter @MrAhmadAwais

๐Ÿ“จ

Developers Takeaway

Stay ahead in the web dev community with Ahmad's expert insights on open-source, developer relations, dev-tools, and side-hustles. Insider-email-only-content. Don't miss out - subscirbe for a dose of professional advice and a dash of humor. No spam, pinky-promise!

โœจ 172,438 Developers Already Subscribed
Comments 20
  • gman100
    Posted on

    gman100 gman100

    Reply Author

    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
    Posted on

    gman100 gman100

    Reply Author

    godoc is bundled with the base Go install but golint isn’t.


  • Karan Harsh Wardhan
    Posted on

    Karan Harsh Wardhan Karan Harsh Wardhan

    Reply Author

    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
    Posted on

    Karan H Karan H

    Reply Author

    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
      Posted on

      Graham Land Graham Land

      Reply Author

      Don’t cut and paste from the browser – try typing the commands in as the quotes are not the standard posix character set


    • gman100
      Posted on

      gman100 gman100

      Reply Author

      Your command has smart quotes try the following
      test โ€“d “${GOPATH}/src/github.com” || mkdir โ€“p “${GOPATH}/src/github.com”


      • gman100
        Posted on

        gman100 gman100

        Reply Author

        Wow, my browser added smart quotes (โ€œโ€) to my last response, you will need normal quotes.


  • William Grisaitis
    Posted on

    William Grisaitis William Grisaitis

    Reply Author

    Typo with `test-d “${GOPATH}/src/github.com” || mkdir -p “${GOPATH}/src/github.com”` :)


  • Kokila Alupotha
    Posted on

    Kokila Alupotha Kokila Alupotha

    Reply Author

    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
      Posted on

      Ahmad Awais Ahmad Awais

      Reply Author

      That makes a lot of sense. Thank you.


      • Patrick
        Posted on

        Patrick Patrick

        Reply Author

        I’ve heard setting GOROOT is not even necessary.


  • Rahul Bohra
    Posted on

    Rahul Bohra Rahul Bohra

    Reply Author

    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
    Posted on

    Rahul Bohra Rahul Bohra

    Reply Author

    Also, need to know your theme name or if its open source then please share the link, would like to use for mine


  • Shankar
    Posted on

    Shankar Shankar

    Reply Author

    – 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
      Posted on

      Ahmad Awais Ahmad Awais

      Reply Author

      Haha. I’m so glad that you found it all useful. :)


  • Weslley
    Posted on

    Weslley Weslley

    Reply Author

    Why you’d created a hidden folder to $GOPATH variable?

    Btw, thank you for homebrew installation support!


  • Mat Jovanovic
    Posted on

    Mat Jovanovic Mat Jovanovic

    Reply Author

    Your golint repo is wrong, I’d switch to golang.org/x/lint/golint

    Everything else is awesome, thanks!!!