go install not creating binary of a package while go get is able to - go

I am on go version go1.11.2 linux/amd64. When the package godog is installed using go get github.com/DATA-DOG/godog/, godog executable is created inside $GOPATH/bin/. All fine till now.
I am creating an application myApp that resides at $GOPATH/src/ in which under the folder vendor, godog package is added. When I try to create a binary out of vendor-ed package, an archive file is created inside $GOPATH/pkg/linux_amd64/myApp/vendor/github.com/DATA-DOG/ as godog.a
How can I create a binary in this scenario? I do not want to do go get again just for the binary.

go install does not automatically install apps in vendor folders, but you may specify a vendored path explicitly if you wish so. So simply run:
go install myApp/vendor/github.com/DATA-DOG/godog/cmd/godog

Related

Why does `go install` on a Github directory work but not file?

So if I have a go module on my local filesystem, I can install a binary by running go install cmd/main.go and it will create a binary called $GOPATH/main as expected. Basically it behave the same as go build but copying the binary to $GOPATH.
However, when I try to install the same module on stored on Github, it fails:
go install github.com/sanbornm/go-selfupdate/cmd/go-selfupdate/main.go
no required module provides package github.com/sanbornm/go-selfupdate/cmd/go-selfupdate/main.go; to add it:
go get github.com/sanbornm/go-selfupdate/cmd/go-selfupdate/main.go
Instead, I need to call go install on the directory for it to properly work:
go install github.com/sanbornm/go-selfupdate/cmd/go-selfupdate
How do I reconcile this behavior difference?

Using Go Modules with packages that require "make install"

I have an external package that apart from the usual go get, needs to run make install in its $GOPATH/src directory in order to use it (performs some makefile and git magic).
Trying to use this package with modules means a copy of it is downloaded to the vendor library using go mod vendor. However, this copy is not a git repository so running make install inside the package's vendor folder fails.
Does this mean that the package cannot be used in a module and I have to revert to using GOPATH?
Does this mean that the package cannot be used in a module
Yes.
Contact the author and make him to check in what the makefile does.

How do I install a go module?

Usually, when i'm in a workspace, all I need to do is go install to install an executable into my pkg folder. However, let's say i'm creating a module outside of $GOPATH/src. I then have a folder called ModuleTest on my desktop that contains the go.mod file. How do I install the package I created so I can use it in other go programs.
I've tried running go get and go install while inside the ModuleTest folder but it doesn't install anything into $GOPATH/pkg or $GOPATH/bin.
EDIT: I guess what i'm asking is, how do I install a go module locally without first pushing it on github and then doing go get
Just use the replace keyword.
It will be something like this:
module github.com/a/b
replace github.com/foo/bar => /Users/YourName/Projects/bar
require (
github.com/foo/bar v1.0.0
)
For it to reflect in $GOPATH/bin you need to do go get -u ....... instead of go get ........
Hope it helps :)

How to remove an installed package using go modules

I've installed a package using go modules (go get in Go 1.13) and now I want to remove it. In the documentation there is nothing about this and in go get docu neither.
Removing the package from go.mod manually doesn't solve the issue so it remains in go.sum.
How should I remove a package in a clean way?
Found it https://go.dev/blog/using-go-modules#removing-unused-dependencies
go mod tidy
So basically, once the package is not being imported in any package you can perform a go mod tidy and it will safely remove the unused dependencies.
And if you are vendoring the dependencies, then run the command below to make the module changes be applied in the vendor folder:
go mod vendor
#jesugmz answer doesn't say, what if you wanna remove a currently using package in go modules.
So, if you're using go modules (you have a go.mod file in your project) and you want to remove a currently using package, check $GOPATH/pkg/mod/ directory and simply remove the package named package#version.
For example, if you have github.com/some/project package installed, you should run the following command:
rm -rf $(go env GOPATH)/pkg/mod/github.com/some/project#v1.0.0
You can find the using package version in go.mod file.

Cannot install docker pkg dependency in Go

I'm trying to use the docker package in one of my Go applications. I'm importing the package as import "github.com/dotcloud/docker" in my script. But when trying to build the dependencies, that is, when I run go get in my project directory, it says:
foo.go:9:2: no buildable Go source files in /home/neville/gocode/src/github.com/dotcloud/docker
Here, my GOPATH is set to /home/neville/gocode, so when doing go get, the package should get downloaded to /home/neville/gocode/pkg, instead of /home/neville/gocode/src. What am I missing here?
github.com/dotcloud/docker isn't a Go package, and that's why there are no source files in that directory.
Import the package you want directly, like so for the registry package:
import "github.com/dotcloud/docker/registry"
Also, go get does download into $GOPATH/src. The installed object files go in $GOPATH/pkg.

Resources