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 — The Composable AI Developer platform · Serverless AI Cloud · Ship agentic AI pipes, tools, and memory with BaseAI — The first Web AI Framework (free, open-source, local-first, deploys serverless, agentic pipes, tools, and memory)

Ex VP DevTools & DevRel Eng. Rapid · Google Developers Advisory Board (gDAB) founding member. 🧑‍💻 AI/ML/DevTools Angel InvestorAI/ML Advisory Board 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 5x 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 and VSCode.pro course. Over 142 million views, 24 yrs Blogging, 108K 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.
💜 Loves his wife (Maedah) ❯ Read more about Ahmad Awais.

👋… Awais is mostly active on 𝕏 @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!!!