11

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 ?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
rellocs wood
  • 1,381
  • 4
  • 21
  • 36
  • I'm quite new to GO ( also English... ), so please give more detail as possible in plain words ,thx~ – rellocs wood Jul 18 '18 at 08:41
  • 1
    Please have a look at the official documentation: https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies – Marco Talento Jul 18 '18 at 09:06
  • 1
    @MarcoTalento: You need to take into account the limits on internet access in China. Some of them are mentioned in the question. For China, https://golang.google.cn may be a better site: [The Go Blog: Hello, 中国!](https://blog.golang.org/hello-china). – peterSO Jul 18 '18 at 09:15
  • What happens when you try the `go get`? Do you get an error, and if so, what is it? – Adrian Jul 18 '18 at 13:16
  • 1
    @peterSO golang.google.cn is exactly what I need! THX! – rellocs wood Jul 19 '18 at 00:50

2 Answers2

24

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.

kkpoon
  • 1,939
  • 13
  • 23
0

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.

Esmaeil MIRZAEE
  • 1,110
  • 11
  • 14