Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Go package manually from source code

Tags:

go

go-micro

goa

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 ?

like image 307
rellocs wood Avatar asked Jul 18 '18 08:07

rellocs wood


People also ask

How do I install and use go packages?

To install a package using go get follow the following steps: Step 1: Make sure to check whether the Golang is installed on your system by checking the version of Go. Step 2: Set the GOPATH by using the following command. Step 3: Now, set the PATH variable with the help of the following command.

How do I add packages to Golang?

Check your GOPATH in environment variables and set it to the directory which contains all Go files. Create a new folder with the name of the package you wish to create. In the folder created in step 2, create your go file that holds the Go package code you wish to create.


1 Answers

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.

like image 119
kkpoon Avatar answered Sep 19 '22 17:09

kkpoon