I am a go newbie. I am trying to install gomobile for evaluation on MacOS BigSur but can't get past the init step.
running go version returns go version go1.17.6 darwin/amd64
Following the directions, the gomobile install appears to work properly (after explicitly adding gomobile to my PATH), but running init or version fails.
gomobile: go install golang.org/x/mobile/cmd/gobind failed: exit status 1
go install: version is required when current directory is not in a module
Try 'go install golang.org/x/mobile/cmd/gobind#latest' to install the latest version
gomobile version unknown: cannot test gomobile binary: exit status 1, no required module provides package golang.org/x/mobile/cmd/gomobile: go.mod file not found in current directory or any parent directory; see 'go help modules'
I'm guessing this has something to do with environment variables but any suggestions and/or help would be appreciated.
I did manage to finally get gomobile set up, but the process was painful and the official "experimental" documentation was incomplete and not at all helpful. Here's the steps that worked for me on MacOS (BigSur):
Follow steps to install GO from website
Install gomobile
go install golang.org/x/mobile/cmd/gomobile#latest
Install Xcode command line tools. If installed but not found, you may need to run the following:
xcode-select -r
Install Android NDK. This can be done via Android Studio’s Tools->SDK Manager. Need to ensure that the installed version is supported by gomobile since the latest version of the NDK is NOT supported by gomobile.
Update shell to include the following exports:
export PATH=$PATH:/Users/mikem/go/bin
export ANDROID_HOME=/Users/mikem/Library/Android/sdk
export ANDROID_NDK_HOME=/Users/mikem/Library/Android/sdk/ndk/23.1.7779620
Create a working directory
mkdir myworkdir
Create a module directory
mkdir mymodule
cd mymodule
Create a .go file in that module directory and give it some content. Note that the package name should be different than the module name or the bind may complain that it can't find anything
package mymodulelib
import "fmt"
func SayHello() {
fmt.Println("Hello from mymodule")
}
From the work directory, initialize the module
go mod init mymodule
Install gobind - it will complain that you should be using the go install method instead of the go get (deprecated) but the go install does not work (at least for me)
go get golang.org/x/mobile/cmd/gobind
Go back into the module directory, initialize and then generate iOS and android code
cd mymodule
gomobile init
gomobile bind -target ios
gomobile bind -target android
Related
Installed using, go get github.com/githubnemo/CompileDaemon and go install github.com/githubnemo/CompileDaemon
When I try to run it using -> CompileDaemon --compile="./folderName"
It gives -> zsh: command not found: CompileDaemon
Note:
I'm using oh-my-zsh.
My GOPATH and GOBIN are not default one's, I set it to goWorkspace
Install Compile Daemon using
"go install github.com/githubnemo/CompileDaemon#latest"
Important:
Ensure that the Compile Daemon executable path(i.e: GOBIN) is included in $PATH.
You can include it by editing your ".bashrc" or ".zshrc" file.
or by "export PATH=$PATH:$GOBIN"
First, don't forget that the use of go get to build and install packages is deprecated (In earlier versions of Go, 'go get' was used to build and install packages. Now, 'go get' is dedicated to adjusting dependencies in go.mod.)
All you need should be go install:
go install github.com/githubnemo/CompileDaemon#latest
That should generate a CompileDaemon executable in your directory named by the GOBIN environment variable.
But you need $GOBIN itself in your $PATH (from your ~/.zshrc for instance):
export PATH="$PATH:$GOBIN"
when I execute below cmd:
go get k8s.io/client-go#v12.0.0
it tells me: "go: k8s.io/client-go#v12.0.0: invalid version: module contains a go.mod file, so module path must match major version ("k8s.io/client-go/v12")"
ok, then I changed the cmd to this:
go get k8s.io/client-go#v12.0.0+incompatible
then again, it still tells me the same error: go: k8s.io/client-go#v12.0.0+incompatible: invalid version: module contains a go.mod file, so module path must match major version ("k8s.io/client-go/v12")
one interesting thing puzzles me that if I add require k8s.io/client-go v12.0.0+incompatible to go.mod and then execute go mod tidy, then client-go v12.0.0 will be downloaded correctly.
My question is: how can I download this specific version of client-go via go get??
Go Version: v1.18
I used the go install command to download client-go
Here are two examples to install the latest or specific version.
go install k8s.io/client-go#latest
go install k8s.io/client-go#v0.25.3
See client-go installation section for more help,
client-go install
how can I download this specific version of client-go via go get
Not at all.
go get is for adding dependencies to your project.
To download source code in a certain version from the internet use git clone and git checkout.
I'm a beginning go user trying to install the go apache arrow module, so I can run the introductory examples in the user guide. When I try to install the library, I receive the following errors:
$ go install github.com/apache/arrow/go#latest
go: github.com/apache/arrow/go#latest:
module github.com/apache/arrow#latest found (v0.0.0-20220326002331-5bd4d8ec279d),
but does not contain package github.com/apache/arrow/go
$ go install github.com/apache/arrow/go#v7.0.0
go: github.com/apache/arrow/go#v7.0.0: github.com/apache/arrow/go#v7.0.0:
invalid version: go/go.mod has post-v7 module path
"github.com/apache/arrow/go/v7" at revision go/v7.0.0
I've been able to install other go packages successfully, so I don't understand why this install is erroring out.
What is the correct invocation of "go install" to install apache arrow?
There is an easy way: assume you have done go mod init in your local project, you can start to write a file and import github.com/apache/arrow/go/v8 Like this example:
https://github.com/apache/arrow/blob/master/go/arrow/_examples/helloworld/main.go
Now you can easily do
go mod tidy && go mod vendor
And the tool should recognize the imports to download and vendorize.
Or you can do explicitly in your project dir,
go get -u github.com/apache/arrow/go/v8
then run the mod tidy and mod vendor
I am trying to setup GoLand correctly to be able to use it with Go.
I'm trying to run the follow simple HelloWorld go project.
package HelloWorldProject
import "fmt"
func main(){
fmt.Printf("Hello")
fmt.Printf("1+1 = ", 1+1)
}
This is my console's results:
GOROOT=/usr/local/Cellar/go/1.10/libexec #gosetup
GOPATH=/Users/jeanmac/go #gosetup
/usr/local/Cellar/go/1.10/libexec/bin/go build -i -o /private/var/folders/r5/rfwd1cqd4kv8cmh5gh_qxpvm0000gn/T/___Hello /Users/jeanmac/go/src/github.com/jpere547/HelloWorldProject/Hello.go #gosetup
Compilation finished with exit code 0
I am on Mac OS and I installed Go using Brew.
Results of brew info go:
go: stable 1.10 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://golang.org
/usr/local/Cellar/go/1.10 (8,150 files, 336.9MB) *
Poured from bottle on 2018-03-22 at 19:38:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb
==> Requirements
Required: macOS >= 10.8 ✔
==> Options
--without-cgo
Build without cgo (also disables race detector)
--without-race
Build without race detector
--HEAD
Install HEAD version
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
https://golang.org/doc/code.html#GOPATH
You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:/usr/local/opt/go/libexec/bin
The GoLand configurations is below:
GOROOT
GOPATH
It looks like you are trying to run a non main package. Specifically, instead of package HelloWorldProject, you should use package main. After that the IDE will be able to not only build but also run the package.
When you do go build something.go or go isntall something.go that only builds/installs the go package to give you an executable. You will need to run that executable.
The easiest way to run simple Golang programs is simply use go run something.go that will run your go file.
As long as your GOPATH is correctly set it should work
you can try to change the package name instead of main
There is an option in configuration to run after build. I think you are missing to set it's configuration.Steps:
1. Go to Run
2. Select "Edit configuration"
3. Select the check-box below output directory field specifying "Run after build".
I need to use the test driven development in Go using "gotests" command.
gotests -all *
This is not working. I did go get -u /github.com/cweill/gotests
and go install. But there is no binary created in $GOPATH/bin.
since there is NO main package, Use this command
$ go get github.com/cweill/gotests/...
this itself download all dependencies for the current package, and creates bin file, after downloading this package. see in $GOPATH/bin there will be a bin file named gotests
for more see HERE
The following worked for me with go v1.19.1
go install github.com/cweill/gotests/gotests#latest
Using go get to install things has been disabled since 1.18. See Deprecation of 'go get' for installing executables
go install github.com/rakyll/gotest
Source: https://github.com/rakyll/gotest