Command not found go — on Mac after installing Go
Asked Answered
R

10

99

I installed go1.5.2 darwin/amd64, but when I run the command go version, I get an error in the terminal zsh: command not found: go.

I added the path export PATH=$PATH:/usr/local/go/bin to the bash profile, but I still get the error (I restarted the terminal btw).

I uninstalled and reinstalled, but no luck.

Ruisdael answered 10/1, 2016 at 16:58 Comment(7)
Do you use bash or zsh?Emasculate
I am using zsh in the command line.Ruisdael
should be adding your PATH variable to ~/.zshrc and not bash profile, the error shows you are using zsh and not bashFesta
You should do echo $PATH to see whether your PATH include /usr/local/go/bin. If not, you've not edited the correct file, or not edited all the relevant files.Orlov
@bjhaid, this worked, thank you so much. I'm assuming if i want to add a workspace path, I need to add this to zshrc file as well. Is this correct?Ruisdael
@Ruisdael I don't know how go tooling works, so I can't answer that questionFesta
@Ruisdael Go doesn't have the workspaces in the way Python might. Better is to use a tool like getgb.io which helps tackle this problem better.Trunks
S
215

Like bjhaid mentioned in the comments above:

This is happening because you must add your PATH to your ~/.zshrc file.

in the ~/.zshrc you should add the line:

export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin

you should then source you .zshrc file:

. ~/.zshrc
Supra answered 29/1, 2016 at 4:19 Comment(3)
I have added the only line which worked for meAldora
In my case $GOPATH wasn't explicitly set so doing $ echo $GOPATH returned nothing. In my .zshrc I had to make the second export be export PATH=$PATH:$HOME/go/bin for things to work.Riyal
export PATH=$PATH:/usr/local/go/bin should be export GOPATH=$PATH:/usr/local/go/binBarong
M
24

I kept running into issues and followed the steps on here and finally got a working solution: http://totzyuta.github.io/blog/2015/06/21/installing-go-by-homebrew-on-mac-os-x/

Install w/brew:

brew install golang

Edit bash_profile and add following paths:

nano ~/.bash_profile

export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/.go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Source it:

source ~/.bash_profile

Then restart terminal

go version

Output: go version go1.12 darwin/amd64

Miscount answered 9/3, 2019 at 17:46 Comment(0)
C
7

For bash, you should edit the .bashrc file and add the abobe mentioned line:

export PATH=$PATH:/usr/local/go/bin
Catenary answered 7/5, 2017 at 7:8 Comment(0)
G
7

Add Go PATH to your ~/.zshrc file. Open file to edit as -

vim ~/.zshrc

in the ~/.zshrc you should add the line:

export PATH=$PATH:/usr/local/go/bin

Once done, close and reopen terminal and you are good to go. For test, you can do -

go version

It will show output something like -

go version go1.15.1 darwin/amd64
Gigantean answered 7/9, 2020 at 8:52 Comment(2)
this is a duplicate answerCurly
@ScottStensland Other answers with .zshrc and GOPATH didn't work with my new installation version 1.18.2, anyways this answer worked, thank you @Pankaj!Matlock
G
6

Add the following line to ~/.bashrc or ~/.bash_profile file at the end on your Mac

alias go="/usr/local/go/bin/go"

And in the Terminal

source ~/.bashrc or source ~/.bash_profile in an existing terminal session. Or to see the new changes you can also re-open a new terminal session.

Goss answered 20/11, 2018 at 16:46 Comment(0)
R
4

The GOPATH environment variable specifies the location of your workspace. If no GOPATH is set, it is assumed to be $HOME/go on Unix systems and %USERPROFILE%\go on Windows. If you want to use a custom location as your workspace, you can set the GOPATH environment variable.

This answer explains how to set this variable on various Unix systems.

GOPATH can be any directory on your system. In Unix examples, we will set it to $HOME/go (the default since Go 1.8). Note that GOPATH must not be on the same path as your Go installation. Another common setup is to set GOPATH=$HOME.

Go 1.13+

go env -w GOPATH=$HOME/go

Bash

Edit your ~/.bash_profile to add the following line:

export GOPATH=$HOME/go

Save and exit your editor. Then, source your ~/.bash_profile.

source ~/.bash_profile

Zsh

Edit your ~/.zshrc file to add the following line:

export GOPATH=$HOME/go

Save and exit your editor. Then, source your ~/.zshrc.

source ~/.zshrc

fish

set -x -U GOPATH $HOME/go

The -x is used to specify that this variable should be exported and the -U makes this a universal variable, available to all sessions and persistent.

Restricted answered 23/3, 2021 at 19:46 Comment(0)
D
3

This is what i did on my mac:

opened the file ~/.zshrc using sudo nano ~/.zshrc then pasted

export PATH=$PATH:/usr/local/go/bin save and exit(ctrl + s, ctrl + x then press y) then ran

. ~/.zshrc go was up and running, verified by typing just go in command line.

Dinky answered 5/2, 2019 at 18:5 Comment(0)
K
1

In my case I was not having ~/.zshrc profile file. Followed below steps to make it work.

Mac os version : Mojave (10.14.6)

Go version : go1.13.1 darwin/amd64

Reference link : https://www.cyberciti.biz/faq/installing-go-programming-language-on-mac-os-x/

As mentioned in link, when i was executing "go env" command, it was throwing error "go command not found". Adding "export PATH=$PATH:/usr/local/go/bin" in "~/.bashrc" profile file didn't do any magic!!

step 1 : Create .zshrc profile under home path.

$ cd /User/xxxx (Eg : /User/tapan)

$ touch .zshrc

step 2 : append 'PATH' with go in .zshrc file.

$ vim .zshrc

$ export PATH=$PATH:/usr/local/go/bin

step 3 : source your .zshrc file

$ source ~/.zshrc

step 4 : execute "go env" command, you should be able to see local environment details.

$ go env

Kithara answered 1/10, 2019 at 7:18 Comment(0)
T
1

try this if your device is a M chipset mac

export PATH = ${PATH}:${GOPATH}/bin:${GOPATH}/bin/darwin_amd64
Tessler answered 18/2 at 6:40 Comment(0)
G
0

If you're using fish, add the following to your fish config found at ~/.config/fish/config.fish:

# Go
set -x PATH "/usr/local/go/bin" "$PATH"

After, be sure to relaunch Terminal or run source ~/.config/fish/config.fish

Gustie answered 29/12, 2023 at 5:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.