Command not found go — on Mac after installing Go

半城伤御伤魂 提交于 2020-04-07 21:54:10

问题


I want to use golang, but I'm having trouble running the go command. 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. Can anybody help me troubleshoot this? I'm not sure if there was an error in the installation, but it downloaded ok. I may have to download an older version of go if this doesn't workout.


回答1:


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

you should then source you .zshrc file:

. ~/.zshrc



回答2:


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




回答3:


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

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



回答4:


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.




回答5:


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.




回答6:


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



来源:https://stackoverflow.com/questions/34708207/command-not-found-go-on-mac-after-installing-go

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!