Unknown subcommand "mod" error while running go mod init - go

I have installed the go language in my ubuntu using sudo apt install golang-go.
It was successfully installed. When i run go version I am getting go version go1.10.4 linux/amd64
but when i tried running go mod init projectName I am getting the following error go: unknown subcommand "mod"
Do I need to install mod package or am i missing something? I have implemented the solution given by christophe in this forum but it didn't work for me.

Preliminary module support was added in Go 1.11, so Go 1.10 knows no mod subcommand.
You need to install a newer, preferably the newest 1.14 version of Go. Get it from the official downloads page. Go 1.10 is not even supported anymore (doesn't receive security patches).
The prepared packages of OSes usually lag behind new releases. I'd advise to always get Go from the official page.

Because preliminary support for go-modules came in version 1.11 and 1.12.
More here
I suggest that you install using the linux build directly from golang

Related

Golang build error 0x80000034 (2147483700)

command I ran: go build -o main
output:
/usr/local/go/pkg/tool/darwin_arm64/link: /usr/local/go/pkg/tool/darwin_arm64/link: combining dwarf failed: unknown load command 0x80000034 (2147483700)
go version: go version go1.16.4 darwin/arm64
Have a look at issue #47269.
load command 0x80000034 corresponds to LC_DYLD_CHAINED_FIXUPS. Support for this load command was added in https://go-review.googlesource.com/c/go/+/312729, which is part of Go 1.17.
You should upgrade to Go 1.17 or above.
As mentioned by #blackgreen, can solve the problem by upgrading to Go 1.17.
However if not wanna upgrade to Go 1.17, can also try to install an AMD version of Go 1.16 and run again. This works for me on my MAC M1.
If you can disable cgo CGO_ENABLED=0 go build -o main it should build with go 1.16
If you are on Mac M1 chip, and if you wanna go 1.16, can also try to install an amd version of the go 1.16. This has been tested and worked fine on my machine.
Reference: https://www.pixelstech.net/article/1637845585-combining-dwarf-failed%3A-unknown-load-command-0x80000034-solution-in-GoLang

Difficulty installing go buffalo using go mod on windows

I am very new to golang. I am trying to work with the gomod. Trying to explore the go buffalo framework. But finding a bit of difficulty in installing that.
What I have done:
I saw that go get is nomore supported for buffalo and so switched to go modules.
Created a module by go mod init github.com/webbuffalotest
Fetched go get -v github.com/gobuffalo/buffalo (on the same directory where I have go.mod file)
Fetched go get -v github.com/mattn/go-sqlite3 (on the same directory where I have go.mod file)
go install github.com/gobuffalo/buffalo
I was expecting a buffalo.exe inside %GOPATH%/bin so that I can add it to my path but didn't find one.
My question is what's wrong? Is the exe not installed or it's somewhere else because of go mod. Any help will be highly appreciated.
I am using windows 10. I am not willing to install package managers as scoop or choco to install buffalo. Thanks for your patience :)
Edited:
Also tried setting set GO111MODULE=on but of no use.
Solved:
My bad, I should have used go install github.com/gobuffalo/buffalo/buffalo instead of go install github.com/gobuffalo/buffalo
github.com/gobuffalo/buffalo is a library; the corresponding binary is (aptly-named) github.com/gobuffalo/buffalo/buffalo.
The go install command you ran should have warned you about that, but didn't because go install used to also be used to cache compiled libraries (it no longer does that in module mode).
I've filed https://golang.org/issue/46912 to add a diagnostic.

cannot find package "google.golang.org/protobuf/cmd/protoc-gen-go"

The page Protocol Buffer Basics: Go says 2 things:
1) Download the package and follow instructions in README
2) Run go install google.golang.org/protobuf/cmd/protoc-gen-go
Following the Download Protocol Buffers points to the release page which has tar and zip files for lots of languages (C++, C#, ...) but not Go. The file protobuf-all-3.12.3.tar.gz has many languages, but not Go. The README says for Go, head off to Go support for Protocol Buffers which says that it has been superseded by module google.golang.org/protobuf. There aren't any installation instructions by the time I've got there, just more general stuff pointing to even more pages. So I tried step (2)
go install google.golang.org/protobuf/cmd/protoc-gen-go
and got
can't load package: package google.golang.org/protobuf/cmd/protoc-gen-go: cannot find package "google.golang.org/protobuf/cmd/protoc-gen-go" in any of ...
I have 9 tabs open on my browser pointing to various Golang Protocol Buffer pages, and I still haven't managed to get going. I've downloaded protoc and got it working ok for Java and Python, but installing Go has got me beat so far. Is there a page that tells me what to do, in a simple way? Once upon a time using the Github repository it was easy, but that was long ago...
Thanks, Jan
Running
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
first before go install seems to have solved it.
Make sure you have a go.mod:
go mod init github.com/org/repo
Have you tried installing the binary with the below command:
go install github.com/golang/protobuf/protoc-gen-go
If you are looking for a specific version, try:
go install github.com/golang/protobuf/protoc-gen-go#v1.3
Note: Make sure you set the GOBIN before you run the above commands
Thanks
Download protoc binary for required OS: github.com => protobuf => releases
Add protoc to $PATH
Install protoc-gen-go to $GOBIN:
user ~ % go install github.com/golang/protobuf/protoc-gen-go
go: finding github.com/golang/protobuf/protoc-gen-go latest
go: downloading google.golang.org/protobuf v1.23.0
go: extracting google.golang.org/protobuf v1.23.0
go: finding google.golang.org/protobuf v1.23.0
Note: to specific version add #v + version
Note: Go Automatically install protoc-gen-go binary to $GOBIN, if $GOBIN did not set, it's equals $GOPATH/bin.
see this.
https://developers.google.com/protocol-buffers/docs/reference/go-generated
you need go version 1.16 or higher. check that.
As pointed out in #jeremyko's comment, you will need Go 1.16 or higher. I personally installed Go from the APT repository, which often has outdated packages. It installed 1.13, so I had problems with installing OpenSnitch.
You can download the latest version from here.

Can't install any GoLang script in Linux

When I try to run any Go script it show me this error
I installed go lang step by step from this link
https://www.tecmint.com/install-go-in-linux/
When I setup go script like this
go get github.com/tomnomnom/waybackurls
I got error like this
github.com/tomnomnom/waybackurls
src/github.com/tomnomnom/waybackurls/main.go:191: u.Hostname undefined
(type *url.URL has no field or method Hostname)
If you are following the guide you linked by copy-pasting commands, you will have installed Go 1.7.3. The function url.Hostname() was added in Go 1.8.
I suggest completely ignoring that guide. Remove /usr/local/go, remove ~/go_projects and undo the path related stuff.
Instead, use the package manager of your OS to install Go.
Most likely, this means you should do either sudo apt install golang (for Ubuntu, Debian, ...) or sudo dnf install golang (Fedora, CentOS, ...).
That will give you the latest version that is supported by distro maintainer (which at the moment is probably 1.11 or 1.12, depending on your distro).
As an alternative to the packagemanager, download the latest version from https://golang.org/dl/.
This approach also gives you an installation that follows the Go ecosystem their conventions for paths (I'm not sure if ~/go_projects was ever a think, but it isn't today).

How to Install old version go-vim plugin

I am a new golang developer. My company uses go 1.10.2, and I hit following error during installing vim-go
Error installing golang.org/x/tools/cmd/gopls: # golang.org/x/tools/internal/lsp/source^#../../../golang.org/x/tools/internal/lsp/source/symbols.go:232:18: ti.EmbeddedType undefined (t
ype *types.Interface has no field or method EmbeddedType
It turns out due to the old go version. https://github.com/fatih/vim-go/issues/2246, https://github.com/golang/go/issues/31864. Since upgrade go version is not an option, the only choice I can think of is to install an old version vim-go that supports go 1.10.2. But I am not sure how to do so.
This is how I install vim-go now:
git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go
then open up vim and run :GoInstallBinaries (where above error show up)
Any suggestions would be great. Since I am neither a vim nor a go person before, more details would be appreciate!
You should try goenv it support multiple version of golang.
Here is the installation guide
https://github.com/syndbg/goenv/blob/master/INSTALL.md
And after installation you can choose and install any version from the list.
Just by typing..
goenv install 1.10.2
Solved it by cloning the repo and checkout to an old commit

Resources