Command not found go — on Mac after installing Go

huangapple go评论94阅读模式
英文:

Command not found go — on Mac after installing Go

问题

我安装了go1.5.2 darwin/amd64,但是当我运行命令go version时,在终端中出现了错误zsh: command not found: go

我在bash配置文件中添加了路径export PATH=$PATH:/usr/local/go/bin,但是我仍然得到相同的错误(我已经重新启动了终端)。

我尝试卸载并重新安装,但是没有成功。

英文:

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.

答案1

得分: 194

bjhaid在上面的评论中提到的:

这是因为你必须将你的PATH添加到你的~/.zshrc文件中。

~/.zshrc文件中,你应该添加以下行:

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

然后你应该加载你的.zshrc文件:

. ~/.zshrc
英文:

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

答案2

得分: 24

我遇到了一些问题,并按照这里的步骤最终找到了一个可行的解决方案:http://totzyuta.github.io/blog/2015/06/21/installing-go-by-homebrew-on-mac-os-x/

使用brew安装:

brew install golang

编辑bash_profile并添加以下路径:

nano ~/.bash_profile

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

执行以下命令使其生效:

source ~/.bash_profile

然后重新启动终端

go version

输出结果:go version go1.12 darwin/amd64

英文:

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

得分: 6

对于bash,您应该编辑.bashrc文件并添加上述提到的行:

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

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

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

答案4

得分: 6

将以下行添加到您的Mac上的~/.bashrc~/.bash_profile文件的末尾:

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

然后在终端中执行以下操作:

在现有的终端会话中执行source ~/.bashrcsource ~/.bash_profile。或者,您也可以重新打开一个新的终端会话以查看新的更改。

英文:

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

得分: 6

Go的路径添加到你的~/.zshrc文件中。打开文件进行编辑,命令如下:

vim ~/.zshrc

在~/.zshrc文件中,你应该添加以下行:

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

完成后,关闭并重新打开终端,你就可以使用Go了。进行测试,可以输入以下命令:

go version

它将显示类似以下的输出:

go version go1.15.1 darwin/amd64
英文:

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

答案6

得分: 4

GOPATH环境变量指定了你的工作空间的位置。如果没有设置GOPATH,在Unix系统上默认为$HOME/go,在Windows上默认为%USERPROFILE%\go。如果你想要将自定义位置作为你的工作空间,你可以设置GOPATH环境变量。

以下是如何在各种Unix系统上设置该变量的说明。

GOPATH可以是系统上的任何目录。在Unix示例中,我们将其设置为$HOME/go(自Go 1.8起的默认设置)。请注意,GOPATH不能与你的Go安装路径相同。另一种常见的设置是将GOPATH设置为$HOME

Go 1.13+

go env -w GOPATH=$HOME/go

Bash

编辑你的~/.bash_profile文件,添加以下行:

export GOPATH=$HOME/go

保存并退出编辑器。然后,执行以下命令使~/.bash_profile生效。

source ~/.bash_profile

Zsh

编辑你的~/.zshrc文件,添加以下行:

export GOPATH=$HOME/go

保存并退出编辑器。然后,执行以下命令使~/.zshrc生效。

source ~/.zshrc

fish

set -x -U GOPATH $HOME/go

-x用于指定该变量应该被导出,-U将其设置为全局变量,可在所有会话中使用并持久化保存。

英文:

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.

答案7

得分: 3

这是我在我的Mac上所做的:

打开文件~/.zshrc,使用命令:
sudo nano ~/.zshrc
然后粘贴以下内容:

export PATH=$PATH:/usr/local/go/bin
保存并退出(按下ctrl + s,然后按下ctrl + x,最后按下y)
然后运行命令:

. ~/.zshrc
Go已经成功安装并运行,
通过在命令行中输入go进行验证。

英文:

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.

答案8

得分: 1

在我的情况下,我没有~/.zshrc配置文件。按照以下步骤使其工作。

Mac OS版本:Mojave(10.14.6)

Go版本:go1.13.1 darwin/amd64

参考链接:https://www.cyberciti.biz/faq/installing-go-programming-language-on-mac-os-x/

如链接中所述,当我执行"go env"命令时,会出现"go command not found"错误。在"~/.bashrc"配置文件中添加"export PATH=$PATH:/usr/local/go/bin"并没有起到任何作用!

步骤1:在主目录下创建.zshrc配置文件。

$ cd /User/xxxx
(例如:/User/tapan)

$ touch .zshrc

步骤2:在.zshrc文件中将'PATH'与go一起添加。

$ vim .zshrc

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

步骤3:加载您的.zshrc文件

$ source ~/.zshrc

步骤4:执行"go env"命令,您应该能够看到本地环境详细信息。

$ go env

英文:

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

huangapple
  • 本文由 发表于 2016年1月11日 00:58:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/34708207.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定