skip to Main Content

I was migrating my Golang programs from windows to Centos 7

It worked perfectly in Windows
but when I tried to compile on centos I get errors like

main.go:20:3: cannot find package "github.com/BurntSushi/toml" in any of:
        /usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
        /root/work/src/github.com/BurntSushi/toml (from $GOPATH)
main.go:15:3: cannot find package "github.com/dgrijalva/jwt-go" in any of:
        /usr/local/go/src/github.com/dgrijalva/jwt-go (from $GOROOT)
        /root/work/src/github.com/dgrijalva/jwt-go (from $GOPATH)
main.go:16:3: cannot find package "github.com/gwlkm_service/config" in any of:
        /usr/local/go/src/github.com/gwlkm_service/config (from $GOROOT)
        /root/work/src/github.com/gwlkm_service/config (from $GOPATH)

kinda new to centos so idk what to do

2

Answers


  1. looks like you have configured your GOPATH, without Go Module, you can use go get [package path] to download imported packages.

    go get github.com/BurntSushi/toml
    go get github.com/dgrijalva/jwt-go
    go get github.com/gwlkm_service/config
    
    Login or Signup to reply.
  2. Precisely

    your go installation on server seems in /usr/local/go and
    your project is in /root/work
    so all your dependencies should be either in /root/work/src or /usr/local/go/src

    now coming to action check your GOPATH with running echo $GOPATH
    assuming it is automatically set to /usr/local/go/src
    If not then follow – How do I SET the GOPATH environment variable on Ubuntu? What file must I edit?

    If everything is ok then in your folder run go mod init

    this will create mod file which will help you in further installations
    look into – https://blog.golang.org/using-go-modules

    then run go get commands as above @beiping96 said

    go get github.com/BurntSushi/toml
    go get github.com/dgrijalva/jwt-go
    go get github.com/gwlkm_service/config

    NOTE – after completing above process you will generate go modules file(same as package.json) and in future you won’t need to care about dependencies

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search