Bee command not found - go

I just started learning golang and beego. Yesterday I installed golang and bee.
I had alot off trouble getting bee command in command line to work. At a point it started to work.
Today I wanted to continue development. But again it cant find bee command.
As far as I know its something with the PATH variable. But everything seems to be right.
Here comes the different informations you might need to help.
Go is installed and works. Go is installed in:
/usr/local/go
My project folder for go development is placed in my documents folder:
/Users/Anders-air/Documents/go
in this folder i have both bin and src. Src contains my project and packages. And inside bin you will find bee (Unix Executable File)
My bash_profile
export GOPATH=/Users/Anders-air/Documents/go
export PATH=$PATH:/Users/Anders-air/Documents/go/bin
Hopes someone can help. By the way I am use OSX.

vim .bashrc insert
export GOROOT=/usr/local/Cellar/go/1.7.4/libexec
export GOPATH=$HOME/GoLang
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

You should have a path variable named GOBIN, and its path is the bin of your go root path. Run:
go install github.com/beego/bee
then bee cmd can be used

It seems like the bee has been removed or not installed the correct way.
After running the get command again everything works.

Related

zsh: command not found: mockgen - golang 1.18 - macOS Monterrey

I'm new to go. Currently I'm using zsh terminal in macOS, just followed the instructions pointed out here https://github.com/golang/mock when installing go mock. However when trying to execute a mockgen command I keep seeing zsh: command not found: mockgen and when navigating in the terminal to my $GOPATH/bin i see mockgen inthere, so I don't know if there's anything else needed.
These are the variables I have configured in my /.zshrc file:
#GO path
export GOPATH="$HOME/Documents/study_projects/go"
export GOBINPATH="$GOPATH/bin"
Idk if GOBINPATH is a proper name for this $GOPATH/bin variable to be exported to the PATH also, aso pointed out in https://github.com/golang/mock (mockgen/gomock) installation instructions. Does anyone of you know what else is needed here, do I need an additional configuration for this mockgen command to work with zsh?
Thank you!
Make sure run below for go 1.16+
go install github.com/golang/mock/mockgen#v1.6.0
Add users/[your_login]/go/bin to .zshrc path
add export PATH=$PATH:$(go env GOPATH)/bin in .zshrc and try again.

After installing go and setting my path, I am still getting an error

After installing golang according to the instructions on the golang website, I set the path as it said to by using export PATH=$PATH:/usr/local/go/bin and whenever I use the command $HOME/go it says bash: /home/ken/go: No such file or directory
I can verify go is installed and I even reset my computer to make sure the changes took place. Does anybody know what I can do to resolve this issue? Am I missing something?
As per the instructions on the Go installation page, you do need to manually create the go folder:
cd $HOME
mkdir go
cd go
Then create your first go program: https://gobyexample.com/hello-world
And run with go run hello-world.go. Should be good ;)

compile: version "go1.9" does not match go tool version "go1.9.1"

I am getting this error when I tried to run an example helloworld code I got onlie.
compile: version "go1.9" does not match go tool version "go1.9.1"
My computer has go1.9.1. What does the error mean and how can I fix this?
If you are installing using OSX homebrew you may need to set the $GOROOT in your .bashrc, .zshrc, etc:
export GOROOT=/usr/local/opt/go/libexec
I had the same error this morning when I updated from 1.9 -> 1.9.1 though according to several post the $GOROOT shouldn't have to be set and I had not set it until today. This may be a bug?
Edit: not a bug, for more details see answer below.
This is a mismatch between the GOROOT environment variable and the default path to your go command. One or the other needs to be changed; the one that needs to be changed depends on the specific setup on your computer. You could determine this by updating your Go to the latest version using your preferred method, running either which go (on Linux/macOS/BSD) or where go (on Windows), and then checking which of the files listed has the newer timestamp.
Linux/macOS/BSD
To change the GOROOT to match the default path of your go command, run type go and strip off the /bin/go part at the end to yield the directory path containing your Go installation. Then, add it to your .bashrc or other appropriate init file like this:
export GOROOT=/path/to/go-installation
To instead change the go command path to match your GOROOT, add this to the bottom of your init file:
export PATH="${GOROOT}/bin:${PATH}"
Windows
To change the GOROOT to match the default path of your go command, run where go take the first line of output, and strip off the \bin\go.exe part at the end. Then, go to "Edit the system environment variables" in Settings, click "Environment Variables...", find the "GOROOT" variable and edit to read the path you created earlier.
To instead change the go command path to match your GOROOT, first save the output of echo %GOROOT%\bin. Then, go to "Edit the system environment variables" in Settings, click "Environment Variables...", and find the
find the "Path" row in the bottom pane, click New, put in the path you created earlier, and finally click Move Up until it's at the top.
All
You'll need to open up a new command prompt to see the effects.
in case you are using mac with homebrew, just run:
brew cleanup
to clean all the legacy package, this fixed my problem.
In mac OS , if you downloaded and installed go package without brew, running brew update commands will cause this problem to occur
for fix this problem you can do :
brew uninstall --ignore-dependencies go
uninstalling go from brew will fix problem
This error happens when you forgot to delete previous golang install ... just delete its directory ... so identify go install location ... on linux issue
type go
typical output is
go is hashed (/usr/local/go/bin/go)
so just remove its grandparent directory ( go install dir not just the go binary )
sudo rm -rf /usr/local/go # NOTE this is not /usr/local/go/bin/go
now just install go and you'll be fine
For M1 Mac, the following steps helped me!
Check for which go from VSCode Terminal and check from system terminal.
from vscode terminal
user#mac % which go
/usr/local/go/bin/go
from my mac terminal
user#mac % which go
/opt/homebrew/bin/go
Whichever corresponds to the GOROOT shown go env, keep it and delete the other one
user#mac % go env GOROOT
/usr/local/go
in this case
rm -rf /opt/homebrew/bin/go
close and reload the vscode and terminal
For Windows delete the GOROOT System variables in the Enviroment Variables and restart the PC.
if you use VsCode, you just add this in setting.json.
"go.goroot": "/usr/local/Cellar/go/1.x.x/libexec",
For me, it's caused by GOROOT env, using gotip before, change to brew version.
# curret go env
cat "$(go env GOENV)"
# make sure this is correct
go env GOROOT
# unset GOROOT if setted before
go env -u GOROOT
you may also want to set a proper GOROOT to match the go version.
In my case, I had a scripts that look like this:
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
Hanging around in my .bashrc/.zshrc file from a previous installation of go / trying to use gvm.
Removing this and restarting terminal solved it for me.
I had the same issue when I used getgo to update my Go version from 1.19 to 1.20. In my case, getgo created a .bash_profile and set its own export path w/c is not consistent with what's in my .bashrc.
#my .bash_profile;
export PATH=$PATH:/home/user/.go/bin
export PATH=$PATH:/home/user/go/bin
#my .bashrc;
export GOROOT=/usr/local/go/
export GOPATH=$HOME/go
export PATH=$PATH:$/home/user/go/bin:$GOROOT/bin:$PATH
SOLUTION:
I just replaced my export PATH in bashrc w/
export PATH=$PATH:$/home/user/.go/bin:$GOROOT/bin:$PATH
<Note the '.go' change w/c is now consistent to what's in my .bash_profile>.
So whether source is ~/.bashrc or ~/.bash_profile, it will always point to the same path for Go. Hope this helps. I'm also new to Go and Ubuntu. I know how painful it is to get these variables right on your own.
Took a simple approach(Linux), I had different versions of Go installed in my system.
$ whereis go
helped me to find the available go runnables, removed all, installed a fresh one and ensured to create a link for this new Go runnable in one of the $PATH folder to ensure below gives the correct version of what installed now.
$ go version

Error "command not found" after installing go-eval

I'm trying to run Go in an interactive mode.
I want to use go-eval for that, I followed their README instructions:
I ran go get github.com/sbinet/go-eval/ successfully
I ran go-eval which resulted in -bash: go-eval: command not found
Some more information:
echo $PATH returns: /usr/local/go/bin:...
echo $GOPATH returns: $HOME/golang
running whereis go-eval returns no output
running go install go-eval returns:
can't load package: package go-eval: cannot find package "go-eval" in any of:
/usr/local/go/src/go-eval (from $GOROOT)
$HOME/golang/src/go-eval (from $GOPATH)
You'll need to add GOPATH/bin to PATH.
PATH="$GOPATH/bin:$PATH"
Update [Go 1.8 and above]: GOPATH will default to $HOME/go. The above will not work if GOPATH is not explicitly set.
To set both, add this to your .profile file:
export GOPATH="$HOME/go"
PATH="$GOPATH/bin:$PATH"
Ran into this issue while using export PATH="~/go/bin:$PATH".
Seems the ~ was causing problems and changing to the full path worked.
Try something like this instead, which won't use a tilde:
export PATH="$HOME/go/bin:$PATH"
Is the binary go-eval in $GOPATH/bin? Are you running the command with $GOPATH/bin/ as your working directory? If not, thats likely the problem.
go get & go install installs go binaries (if any) in $GOPATH/bin
Check $GOPATH/bin for the go-eval binary. If its there, try running it from $GOPATH/bin with ./go-eval. If that works, you're good.
In future, if you wish to run go binaries found in $GOPATH/bin from anywhere in your shell, add the following to your .bashrc or profile:
export PATH=$PATH:$GOPATH/bin
Then restart your terminal or run . ~/.bashrc or . /etc/profile
When running go install go-eval I get:
can't load package: package go-eval: cannot find package "go-eval" in any of:
/usr/local/go/src/go-eval (from $GOROOT)
$HOME/golang/src/go-eval (from $GOPATH)
You get the above error because go-eval is not in $HOME/golang/src/go-eval. Running go get github.com/sbinet/go-eval/ will download the source to $GOPATH/src/github/sbinet/go-eval/. If you want to run go install go-eval, you have to specify the package name relevant to its position in the directory hierarchy in $GOPATH/src.
e.g.
go install github/sbinet/go-eval
I'd like to add this in addition to the answers given.
As a helpful tip, uou can always test your commands with the which command.
Such as: which go
If the command is not found, you know you have a PATH problem you need to address first.
Then you can focus on finding the command with the find command.
Such as: find / -name "go" -print 2>/dev/null
The first slash is the directory to start the search, the argument to the -name is the command you're looking for and the -print gets a good results look. the 2>/dev/null sends results of directories that are not accessible to neverland (null) so that you do not need to see a bunch of errors.
Using this process helps you quickly find the command in question and then you can add it to your PATH env variable and it becomes accessible as stated in the other answers.
All above answers are self explaining. Over and above those I would like to add that by default you can access only those commands from terminal without path to binary whose bin folder is added to the environment variable, be it linux, mac or windows.
Else you will have to specify the path to bin folder of that software followed by the binary name. For instance in your case <path_to_bin_folder>/go-eval.
This is the most common reason that you are not able to execute that command directly from the command line. Please remember this and try this before searching for answers online because this will most probably solve your issue. All you have to know is the installation path.
So, write the following into the rc or profile file for your terminal and save, example for zsh it is ~/.zshrc, for bash it is ~/.bash_profile or ~/.bash_rc.
export GOPATH="$HOME/go"
export PATH=$PATH:$GOPATH/bin
Now although the file is saved but the changes will not reflect immediately. You have to source the profile file as mentioned above. For this type source ~/.zshrc. You should now be able to run the command directly from command line now. Even if the problem still persists try quit the terminal session and logging off and then logging in.
In case you want to add path to bin folder for other packages, you can append it to the $PATH environment variable using :. So for example if you want to add path to java binary as well, then just do
export PATH=$PATH:$JAVA_HOME/bin
Also it is a good practice to define the path to root folder of a package in its separate environment variable(example $GOPATH="$HOME/go"). In case if the installation path changes in future then you'll just have to update the environment variable related to that binary (example just update, $GOPATH="newpath") and your command will work as previously, since the change in $GOPATH will reflect in $PATH.
add those line in to ~/.zshrc
export GOPATH="$HOME/go"
export PATH=$PATH:$GOPATH/bin
run source ~/.zshrc

Go: "stat hello.go: no such file or directory"

Just installed Go on Mac OS X, Yosemite Version 10.10.3, as explained in the Getting Started page of the official website:
Mac OS X package installer
Download the package file, open it, and follow the prompts to install
the Go tools. The package installs the Go distribution to
/usr/local/go.
The package should put the /usr/local/go/bin directory in your PATH
environment variable. You may need to restart any open Terminal
sessions for the change to take effect.
I am now in the Test your installation section, which states:
Check that Go is installed correctly by building a simple program, as
follows.
Create a file named hello.go and put the following program in it:
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n") }
Then run it with the go tool:
$ go run hello.go
hello, world
If you see the "hello, world" message then your Go installation is
working.
So, I created a hello.go file and, since I could not (ie: did not know how to) access the /usr/local/go/bin directory, I saved it on my desktop.
Obviously, I got the following error message:
stat hello.go: no such file or directory
So, where should I save my Go files to be able to run them?
UPDATE: after some research, I stumbled upond this video, explaining how to set the GOPATH.
If I want my Go workspace to be in user/code/go, how should I write my export GOPATH= command?
if your are using docker compose up/down to build image. You need to run
docker compose build
after changes in Dockerfile.
In my case, it was as simple as right clicking the file, and then clicking 'open in integrated terminal.' Then, to run your file type 'go run filename.go'
The GOPATH and PATH environment variables
The GOPATH environment variable specifies the location of your workspace. It defaults to a directory named go inside your home directory ($HOME/go).
If you really want to change your GOPATH to something else add GOPATH to your shell/bash/zsh initialization file .bash_profile, .bashrc or .zshrc.
export GOPATH=/something-else
Add GOPATH/bin directory to your PATH environment variable so you can run Go programs anywhere.
export PATH=$PATH:$(go env GOPATH)/bin
Following the explanation of Andrew Gerrand in Writing, building, installing, and testing Go code, I configured my Go workspace as follows:
1. Create workspace
First, since I want my Go code to be in my_user_name/code/go, I started by creating the corresponding folder:
$ cd code
$ mkdir go
2. Setup GOPATH
Then I configured the GOPATH:
$ cd
$ export GOPATH=$HOME/code/go
$ cd code/go
3. Add files to workspace
Last, I manually (through the Finder) moved my hello.go file into the workspace and ran:
$ go run hello.go
Worked like a charm.

Resources