Command not found - Oh-My-Zsh - macos

I recently installed zsh and oh-my-zsh in my Mac. Now when I try to run a maven command from the terminal, I am getting the following error.
$ mvn install
zsh: command not found: mvn
I have installed Apache maven in /Applications directory. Currently my .zshrc file looks like below.
plugins=(git brew pip mvn mysql-macports python sublime tmux osx)
# ####################
# Maven Config Options
# ####################
export M2_HOME=/Applications/apache-maven-3.3.3
export PATH=$PATH:M2_HOME/bin
As seen above, I appended location of maven installation to the path. But I am still getting errors. Any help is appreciated.

Question:
➜ ~ mvn
zsh: command not found: mvn
Answer:
step 1:
vim ~/.zshrc
step 2:(Add at the end of the file)
source ~/.bash_profile;
step 3:(Execution shell)
> source ~/.bash_profile
You can use mvn :
➜ / mvn
[INFO] Scanning for projects...
.......

Just add:
source ~/.bash_profile
to .zshrc

I had a similar problem after installing oh-my-zsh, but for adb command.
Looks like the PATH is shortened when oh-my-zsh is installed. I solved it using following steps.
Open the .zshrc file
sudo nano ~/.zshrc
Look for # User configuration
Un-comment the following line:
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
Save the file.
source ~/.zshrc
Give this one a try for other similar command not found errors.

Try below steps:
Open terminal and run command vi ~/.zshrc
Add below lines in file:
export M2_HOME=/Users/<username>/Downloads/apache-maven-3.6.3
export PATH=${M2_HOME}/bin:${PATH}
export PATH
Save file successfully
Open another terminal instance & run command mvn -version
It should work!

Step 1: open zshrc file
sudo nano ~/.zshrc
step 2: add 'mvn' in plugins section
plugins=(git zsh-autosuggestions mvn)
step 3: add maven configuration in zshrc file. (make sure your apache maven extract directory. I have extracted in /opt folder)
# Maven Config Options
export M2_HOME=/opt/apache-maven-3.8.4
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
step 4: save the chnages
ctrl+o
ENTER
ctrl+z
Step 5: reload zshrc file
source ~/.zshrc
Step 6: go to terminal and verify
mvn -v
Output :
Apache Maven 3.8.4
Maven home: /opt/apache-maven-3.8.4
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-
openjdk-amd64 Default locale: en_IN, platform encoding: UTF-8 OS name:
"linux", version: "5.4.0-89-generic", arch: "amd64", family: "unix"

First, as 4ae1e1 pointed out, you missed the $ in PATH=$PATH:M2_HOME/bin
Second, don't forget to run source ~/.zshrc to take the settings into effect instantly.

As mentioned by #4ae1e1 in his comment, $ have to be added before M2_HOME while referring it in the PATH variable, as follows:
export M2_HOME=/Applications/apache-maven-3.3.3
export PATH=$PATH:$M2_HOME/bin/
Once added, as others suggested, source the ~/.zshrc file.

I faced the exact same issue, this is what worked for me:
sudo nano ~/.zshrc
add this:
export PATH=your maven path/apache-maven-3.6.3/bin:/usr/bin:/bin:/usr/sbin:/sbin
Ctrl+X, select "Y", Press Enter
source ~/.zshrc
Validate: mvn -version

On macOS, you can add the following to your .zshrc file.
If you have not, download maven from https://maven.apache.org/download.cgi
# Maven
export PATH=/opt/apache-maven-3.8.3/bin:${PATH} # you could have it in a different directory
To edit .zshrc, you can use an existing text editor such as vim.
$ cd ~
$ vim .zshrc
Use i to insert the export statements. Once inserted, use escto exit insert mode. Then use :wq! to save and quit the editor. Finally, source the file to see the effects of your new changes.
$ source .zshrc
Now try mvn and you should see something like this.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.049 s
[INFO] Finished at: 2021-10-11T13:34:20-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException

I think the answers above are too deep. It could be that the person does not have Maven installed on their Local PC. So please run the command below on your terminal
brew install maven
Afterwards on your IntelliJ or the terminal where the project is located run the command
mvn clean install
Use the command to double check if it was installed
mvn --version

vi ~/.zshrc
add source ~/.bash_profile to ~/.zshrc file, after the line source $ZSH/oh-my-zsh.sh
open up a new terminal tab and execute mvn, and it will start working.

I had the same issue. So created .zshrc file and added below in that file.
export M2_HOME=/Users/gandharavmehra/Desktop/Development/Tools/apache-maven-3.6.3
export PATH=$PATH:$M2_HOME/bin
after this
gandharvmehra#MacBook-Pro ~ % source ~/.zshrc
close the Terminal and open again
gandharamehra#MacBook-Pro ~ % mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
it should work 100 percent

First of all Download Maven from here https://maven.apache.org/download.cgi
and extract it and go and open your zshrc with nano:
nano ~/.zshrc
and paste these lines inside the file:
export M2_HOME="/Users/sanaebadi/Downloads/apache-maven-3.8.7"
PATH="${M2_HOME}/bin:${PATH}"
export PATH
**
you have to make sure that you put your correct USER name instead of
my userName (sanaebadi)
**
and you have to make sure from the version and directory of your maven
that you already downloaded.
**
**
and relaunch the file after it : source ~./zshrc
and run this command to make sure you installed the maven on your system:
mvn -version
you must to see some lines start with :
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /Users/sanaebadi/Downloads/apache-maven-3.8.7 ...
.....
...
Done!

Combining other answers I got adb working on mac and zsh appending these two path lines to .zshrc:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# this are for Android Studio adb:
export PATH=~/Android/sdk/tools:$PATH
export PATH=~/Android/sdk/platform-tools:$PATH

Actually, .bash_profile is for /bin/bash shell, for your /bin/zsh shell, the file is called .zprofile, you should do the same thing in .zprofile as in .bash_profile

I have similar issue today with mvn command not found
In my example problem was with incorrect path - I missed one / at the beginning of the path
.zshrc before change:
export MAVEN_HOME=home/user/Tools/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
good to verify if maven path exists. In my case it was error using command below
ls $MAVEN_HOME
.zshrc after fix one line
export MAVEN_HOME=/home/user/Tools/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
reload .zhsrc
source .zshrc
mvn command found

If you are running Catalina you will face this problem often.
Open your terminal
Just copy all your Path variables and create a .zshrc file (touch .zshrc)
open it (open ~/.zshrc) and paste them there,
save and refresh your .zsrhc file ( source ~/.zshrc).
I found this Video very helpful to solve related problems.

Install Maven on Mac OS. Download the latest version from the Apache Maven site and select the Maven binary tar.gz file, for example, apache-maven-3.8.4-bin.tar.gz.
Then we extract the archive to our desired location.
Adding Maven to the Environment Path
First, let's open the terminal and switch to the directory where the files were extracted to and then log in as superuser or use below commands with sudo.
Second, we need to remove the tar.gz archive:
rm Downloads/apache-maven*bin.tar.gz
Third, we have to fix the permissions and switch the Maven contents:
chown -R root:wheel Downloads/apache-maven*
mv Downloads/apache-maven* /opt/apache-maven
Then, let's archive the Admin session and add Maven binaries to the path and append:
exit
nano $HOME/.profile
export PATH=$PATH:/opt/apache-maven/bin
Finally, we use Ctrl+x to save and exit from nano.
To load the new setup, let's run:
bash
Now, we test if Maven is installed successfully using the command below:
mvn -version
We are now ready to use Maven on our Mac OS.
Reference : How to Install Maven on Windows, Linux, and Mac

If you're on a mac you can use Homebrew to install maven and all it's paths
Use:
brew install maven

If you want to configure intelliJ terminal with a custom Terminal or if you want fix "command not found",
follow these steps:
Click > File
Click > Settings
Click > Tools
Click > Terminal
Edit "Shell path" # "Application Settings", change current path with:
C:\Users\Work\AppData\Local\Programs\Git\bin\sh.exe --login
// The path you may have differs based on your OS, in example: "installationPath\Terminal Folder\bin\sh.exe --login"
Click > Apply
Click > Ok
I used git bash but technically it should work with every terminal. Do not forget to add --login after the *.exe

in my case it was a syntax error:
The wrong usage was like this:
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
export PATH="$PATH:/Applications/Webstorm.app"
I updated:
export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"
export PATH="/Applications/Webstorm.app:$PATH"
and now it works

step 1:
vim ~/.zshrc
step 2:(Add at the end of the file)
source ~/.bash_profile;
step 3 : (Save changes in Vim)
:wq!
step 4:(Execution shell)
> source ~/.bash_profile

Best solution work for me
Open Finder-> go to folder /Users/ /usr/local/bin
open .zshrc with TextEdit
.zshrc is hidden file so unhide it by command+shift+. press
delete file content and type
export PATH=~/usr/bin:/bin:/usr/sbin:/sbin:$PATH
and save
now
zsh: command not found Gone

Related

Is there a robust way to set MAVEN_HOME in my ~/.zshrc without specifying the version number? (MacOS)

Context: I install maven with brew install maven
In my ~/.zshrc I have:
# Maven (mvn --version)
export MAVEN_HOME="$HOME/usr/local/Cellar/maven/3.6.3"
export PATH=$MAVEN_HOME/bin:$PATH
Is there a way to set my MAVEN_HOME in a way that allows me to not have to increment it when Maven is upgraded to 3.6.4?
It is somewhat tedious to have to go into my config file and update it every time I update Maven! :)
This would also help an onboarding/setup script that could download maven and programmatically set up a ~/.zshrc or ~/.bashrc config
What i have done to solve this problem is to create a symbolic link that points to maven installation version.
ln -s maven_3.6.4_path maven_slink
And set the MAVEN_HOME=maven_slink in configuration file. And every time i need to change maven version all i have to do is drop maven_slink and create a new maven_slink that points to the maven installation. I don't need to go change configuration files every time I install a new version of maven.
Per #chepner: /usr/local/bin/mvn is a symlink to the latest installed version when installed via homebrew.
I changed export MAVEN_HOME="/usr/local/Cellar/maven/3.6.3/mvn" to export MAVEN_HOME="/usr/local/bin/mvn" in my ~/.zshrc config and everything is good to go.
I work on windows and i have created folder dev-env and the path of this folder i have added in PATH variable.
I have installed the version of java jdk8, jdk9, jdk11, jdk13.
I have created bat files and place them in dev-env : jdk8.bat ,jdk9.bat, jdk9.bat, jdk11.bat and jdk13.bat.
Inside a bat files I do the switch of version of java.
#echo off
set JAVA_HOME=path to jdk version
set PATH = %JAVA_HOME%\bin+PATH
java -version
Same thing in maven . I created different bat files maven3.bat, maven36.bat.
#echo off
set MAVAEN_HOME=path to jdk version
set PATH = %MAVEN_HOME%\bin+PATH
mvn -version
So , If i want to switch from one version to another. I open the cmd and the run the bat file that has the version that i want.

mvn: command not found - terminal

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

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

How to add Apache Maven to PATH permanently

When I add Apache Maven to PATH using
export PATH=/opt/apache-maven-3.3.9/bin:$PATH
and then check echo $PATH
I can see that bin was added to PATH. However if I repeat echo $PATH later, it disappears from PATH and mvn --version returns:
The program 'mvn' can be found in the following packages:
* maven
* maven2
How to add maven to PATH permanently?
put export PATH=/opt/apache-maven-3.3.9/bin:$PATH in ~/.bashrc

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