How to install Go package manually from source code

25.3k views Asked by At

I'm living in China and is not able to download & install GO package through command (event I use the vpn network):

 go get -u <repo_url>

but I can access the repo_url and downloand its source code. So my question is can I put the scource code under src folder and run commamd ? :

go install 

if yes, what's the different betweeen the two way ?

2

There are 2 answers

0
kkpoon On BEST ANSWER

for example, you have the repo_url at https://github.com/hello/example

You can do go get manually by

$ cd $GOPATH
$ mkdir -p src/github.com/hello
$ cd src/github.com/hello
$ git clone https://github.com/hello/example.git
$ cd example
$ go install

the binary will install into $GOPATH/bin

if the go program of the repo_url depends on other go package. you have to manually get it and put it to correct path location too.

0
Ishmael MIRZAEE On

Two things are important when one looks to get a required package manually,

  1. Path to the package repository; for example, github.com/golang/crypto.git package is hosted on Github. However, when using on code should import as golang.org/x/crypto/bcrypt

    Google the required package

  2. Path in the $GOPATH. In this example, the repository should be cloned inside golang.org directory and inside the appropriate directories. To me, the solution to find the path is running code and read the errors for missing modules/packages.