-1

I am trying to build a project from github source code. I have found some source code importing a package something like below:

import (
    "os"

    "github.com/bivas/rivi/commands"
    "github.com/mitchellh/cli"
)

However, while building a project every time it throws an error:

user-MacBook-Pro:rivi user$ go build rivi.go
rivi.go:6:2: cannot find package "github.com/bivas/rivi/commands" in any of:
        /usr/local/Cellar/go/1.7.5/libexec/src/github.com/bivas/rivi/commands (from $GOROOT)
        ($GOPATH not set)
rivi.go:8:2: cannot find package "github.com/mitchellh/cli" in any of:
        /usr/local/Cellar/go/1.7.5/libexec/src/github.com/mitchellh/cli (from $GOROOT)
        ($GOPATH not set)

how to build this project. Currently I am trying to build this one project into my system.

EDITED:

After running this command go install or go get:

package github.com/bivas/rivi/commands: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/connectors/github: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/autoassign: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/automerge: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/commenter: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/labeler: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/locker: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/sizing: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/slack: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/status: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/bivas/rivi/engine/actions/trigger: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/mitchellh/cli: cannot download, $GOPATH not set. For more details see: go help gopath
Baba ramdev
  • 61
  • 1
  • 3
  • You need to pull the package's dependencies using `go install` or `go get` as answered [here](https://stackoverflow.com/questions/30295146/how-can-i-install-a-package-with-go-get). You may also want to go through the [getting started](https://golang.org/doc/install) page. – Marc Dec 28 '17 at 10:33
  • 4
    Possible duplicate of [How can I install a package with go get?](https://stackoverflow.com/questions/30295146/how-can-i-install-a-package-with-go-get) – Jonathan Hall Dec 28 '17 at 10:36
  • I tried running this but getting few errors, request you to go throught my updated questions – Baba ramdev Dec 28 '17 at 10:43
  • 2
    The output clearly tells you: "cannot download, $GOPATH not set.". Please read through the getting started page linked above. – Marc Dec 28 '17 at 10:50
  • 1
    You should also update to a current version of Go. GOPATH has a default setting now. – JimB Dec 28 '17 at 12:39

2 Answers2

4

This question is a few years old now. I was experiencing the same problem. The solution for me was that I needed to run go mod init [name_of_main_go_file], which creates the go.mod file. Then you can run go run .

https://golang.org/doc/tutorial/getting-started#call

Tom
  • 51
  • 3
  • Thanks, I spent HOURS looking for the answer. This worked for me: `go mod init mything.go` `go mod tidy` `go run mything.go` – PJ Brunet May 03 '22 at 03:36
0

This problem common if you haven't setup any go path yet. It is necessary.

I am assuming from the command line snap of yours, that you are a UNIX user. Googles official doc recommend that you setup your go path manually . $GOROOT is optional but $GOPATH has to be set if you are trying to get third party libraries.

Edit your ~/.bash_profile to add the following line:

export GOPATH=$HOME/work

Then logout and login or use source ~/.bash_profile You can read more from here. Assuming your Golang package directory is in work folder inside your home directory. The directory structure of work folder has to look like this,

  • work
    • src
    • pkg
    • bin
sh0umik
  • 1,549
  • 2
  • 17
  • 27