mvn: command not found - terminal - spring

I am using a Mac Pro machine and want to install maven. So here is what I am doing. First I download the appropriate .zip. I unzip it and in terminal I type
Theodosioss-MacBook-Pro:~ theo$ export M2_HOME=/Users/theo/apache-
maven-3.5.4
and
Theodosioss-MacBook-Pro:~ theo$ export
PATH=$PATH:/Users/theodosiostziomakas/apache-maven-3.5.4
Then I check if maven is installed but I get this.
mvn --version
-bash: mvn: command not found
How to properly fix this?

First you need to add maven path to your PATH variable correctly,as others have said
export PATH=/YOUR_LOCAL_LOCATION/apache-maven-3.5.4/bin:$PATH
then you need to call source /etc/profile(pay attention to check the user type,root or no root) to make it into effect and then open a new terminal for test

Try
export PATH=$PATH:/Users/theodosiostziomakas/apache-maven-3.5.4/bin
mvn executable is inside bin folder.

You have not indicated proper dir, try as below
export PATH=/YOUR_LOCAL_LOCATION/apache-maven-3.5.4/bin:$PATH

The following works for me.
Changes are done to .bash - .profile did not work on my mac
Update the config in ~/.profile
export M2_HOME=<PATH>/apache-maven-X.Y>Z
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

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.

Not able to execute build.xml from my Mac terminal. It gives -bash: ant: command not found

Not able to execute build.xml from my Mac terminal. It gives -bash: ant: command not found . I am trying to give this command from the directory where my build.xml is there. But still it is giving me the error. But good thing is that, I am able to execute it from my eclipse.
Tried executing
source setAppPath.sh
. setAppPath.sh
But it is not recognizing PATH too.
This is what I have in my .bash_profile.
export KAPSEL_HOME=/Users/Bindu/SAP/MobileSDK3/KapselSDK # Apache Ant export ANT_HOME = /Users/Bindu/apache-ant-1.10.1 # Export to PATH
export PATH=$PATH:$KAPSELHOME/bin:$ANT_HOME/bin –
Your missing ant's bin directory from your path, which makes me think you're also missing ANT_HOME.
You need to go to your home directory end edit your .bash_profile file, make sure you add this after everything that's already in there.
ANT_HOME=/directory_where_ant_is_installed/actual_ant_directory
PATH=$PATH:$HOME/bin:$ANT_HOME/bin
export ANT_HOME PATH

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

Bee command not found

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.

Cannot set $GOPATH on Mac OSX

I'm trying to set my $GOPATH variable to run some example code on my machine:
$ smitego-example go run main.go
main.go:5:2: cannot find package "github.com/#GITHUB_USERNAME#/smitego" in any of:
/usr/local/go/src/pkg/github.com/#GITHUB_USERNAME#/smitego (from $GOROOT)
($GOPATH not set)
$ smitego-example export $GOPATH=$HOME
-bash: export: `=/Users/#OSX_USERNAME#': not a valid identifier
Contents of github.com/#GITHUB_USERNAME#/smitego/smitego.go:
package smitego
How can I set my GOPATH so it works always and forever?
Update, as of Go 1.8: If you're installing Go 1.8 (released: Feb 2017) or later, GOPATH is automatically determined by the Go toolchain for you.
It defaults to $HOME/go on macOS (nee OS X) - e.g. /Users/matt/go/. This makes getting started with Go even easier, and you can go get <package> right after installing Go.
For the shell: (the manual method)
~/.bash_profile should contain export GOPATH=$HOME/go and also export PATH=$GOPATH/bin:$PATH. The use of the $ is important: make sure to note where I've used it (and where I have not).
For Sublime Text:
Sublime Text menu > Preferences > Package Settings > GoSublime > Settings: User
{
"shell": ["/bin/bash"],
"env": {"GOPATH": "/Users/#USERNAME#/go/"},
}
Make sure your GOPATH is not set to the full path of the package; just the root of your go folder where src, pkg, and bin reside. If you're not using GoSublime, I'd suggest installing that first.
The accepted answer didn't work for me. I investigated and found the cause: I am using zsh, not bash.
I need to add the following two lines to ~/.zshrc:
export GOPATH=/Users/username/go
export PATH=$GOPATH/bin:$PATH
You don't put the $ prefix on a variable when you're assigning it, only when you're reading it.
export GOPATH=$HOME
To make this permanent, put the command in your .bash_profile.
That will work for Terminal shells. If you need to set environment variables that will affect GUI applications, see Environment variables in Mac OS X
Download and install Go tools
https://golang.org/doc/install
Setup Go workspace
mkdir $HOME/go && cd $HOME/go
mkdir bin pkg src
Setup Go environment
sudo vi ~/.bash_profile
export GOPATH=$HOME/go
PATH=$PATH:$GOPATH/bin
Test by creating, building and running a Go project
mkdir -p $GOPATH/src/github.com/todsul/hello
touch $GOPATH/src/github.com/todsul/hello/hello.go
go install
hello
The http://www.golang-book.com/guides/machine_setup#osx
only has instructions for setting the path on ~/.bashrc, not ~/.bash_profile which thanks to this thread was able to get my example file to build.
export GOPATH=$HOME
export PATH=$PATH:$GOPATH/bin
Other Mac users need to add the above to their ~/.bash_profile.
After installing go with brew or with package this solved my problem:
export GOROOT="/usr/local/go"
export GOPATH="$HOME/Documents/goWorkSpace"
export PATH="$HOME/Documents/goWorkSpace/bin:$PATH"
on macOS High Sierra Version 10.3.3, Go[go version go1.10.1 darwin/amd64] Installed here :
Added following on :~/.bashrc
export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin
and then Go Works
People working with the latest macs and above Catalina version,
you guys need to update the .zshrc file instead of .bash.
Add the following two lines to ~/.zshrc:
export GOPATH=/Users/username/go
export PATH=$GOPATH/bin:$PATH
it should work.!!
This got change a while back, please refer to the link below to understand why .zshrc and not .bash_profile
https://eshop.macsales.com/blog/56921-moving-from-bash-to-zsh-terminal-changes-in-macos-catalina/

Resources