Cobra init not working,: Command not found


I am following this guide.

***@pop-os:~/go/src/foo$ cobra init --pkg-name foo
Command 'cobra' not found, but can be installed with:
sudo apt install cobra

My setup:

I have go 1.16 installed

$ go version 
go version go1.16.3 linux/amd64

my $GOPATH is set to ~/go

$ go env

What I have done:
I used the command

$ go get -u

In my bin’s dir I now find cobra

***@pop-os:~/go/bin$ ls

What am I doing wrong?



~/go/bin/cobra init --pkg-name foo

or keep reading to learn how to to make the cobra command available on the command line.

This seems to be an issue of $PATH configuration. Because the cobra command is not found, the path ~/go/bin is not part of the $PATH variable. One can add the path like this:

export PATH="~/go/bin:$PATH"

and then use the cobra command on the command-line. One can add that export ... command to ~/.bashrc or a similar file to have the PATH configured properly on startup.

Answered By – jakub

Answer Checked By – Mildred Charles (GoLangFix Admin)

Leave a Reply

Your email address will not be published.