A story about go get but stumbling immediately after being assigned with command not found

For busy people

Solution (1): Pass through the path

$ export GOPATH=$HOME/go;
$ export PATH=$PATH:$GOPATH/bin;

If it's just not in the path, this will solve it.

Solution (2): Copy the binary dropped in $ GOPATH/bin by go get to $ GOROOT/bin

However, this is the conclusion of this article.

This time, I put a symbolic link in $ GOROOT to make it easier to switch the version of Go, and I could not go get the binary (executable file) in the execution environment.

Click here for solution

Background

At that time, I got a new MacBook PRO (loaned) and was supposed to develop an API made by Go at my place of assignment, so I was excited to build a development environment for Go.

I built the environment as I was told (without knowing that I would stumble later), built it, and ran the unit test at hand. I passed! "Okay, now you can be part of the team as a developer ..." I left work on that day. I left the company with the determination "I'll do my best from tomorrow!"

In addition, I was informed that the project I was supposed to participate in used an ORM called sqlboiler. With raw SQL, I haven't dealt with ORMs other than ActiveRecord properly, so I was thinking of touching sqlboiler immediately.

Try

With reference to the above, go get the necessary packages.

$ go get -u -t github.com/volatiletech/sqlboiler
$ go get github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql

Now that you've installed what you might need, run the sqlboiler command!

$ sqlboiler psql

But here for some reason I get angry without sqlboiler

$ sqlboiler psql
-bash: sqlboiler: command not found

command not found ... ? Hmm ...? I checked it while thinking that I did go get.

$ ls $GOPATH/bin
sqlboiler-psql*    sqlboiler*Others omitted

that? Is there? why? After that, the time melts as it begins to grow.

Search for the cause

First, check GOPATH

$ echo $GOPATH
/Users/y-kanai/go

HM. What about GOROOT?

$ echo $GOROOT
/Users/y-kanai/goroot

What is goroot ...? You don't know that? That's why

$ ls -la
drwxr-xr-x   5 y-kanai  931577470     160  7 19 23:21 go/
drwxr-xr-x@ 21 y-kanai  931577470     672 12 23 16:51 go1.13.14/
lrwxr-xr-x   1 y-kanai  931577470      25  8  4 12:11 goroot@ -> /Users/y-kanai/go1.xx.xx/

Ah! I'm posting a symbolic link! Complete understanding! !! !!

That means there is no sqlboiler in $ GOROOT/bin ..

$ ls $GOROOT/bin
scene...

In other words, the cause of this time was that I put a symbolic link in $ GOROOT to make it easier to switch the version of Go, and I could not go get the binary to the execution environment.

If you copy the prepared document and paste it, you will not notice it.

solution

Copy the binary (executable file) dropped in $ GOPATH/bin by go get to $ GOROOT/bin!

$ cp $GOPATH/bin/sqlboiler $GOROOT/bin/
$ cp $GOPATH/bin/sqlboiler-psql $GOROOT/bin/

$ ls $GOROOT/bin/
go*             gofmt*          sqlboiler*      sqlboiler-psql*

Execute the sqlboiler command!

$ sqlboiler psql
.
.
.

Alright, the solution for the time being! It took almost an hour to get to this point.

Looking back

Brain death copy is not good. Reflection.

Those who are using while switching between multiple versions of Go, If there is another good way, please teach me. that's all!

Recommended Posts

A story about go get but stumbling immediately after being assigned with command not found
A story about stumbling through PATH after installing anaconda
A story about putting Chrome OS (not Chromium) on surface GO
A story about machine learning with Kyasuket
gqlgen command does not work with go gqlgen
A story about implementing a login screen with django