Command not found - Oh-My-Zsh

156,738

Solution 1

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... .......

Solution 2

Just add:

source ~/.bash_profile

to .zshrc

Solution 3

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.

  1. Open the .zshrc file

    sudo nano ~/.zshrc
    
  2. Look for # User configuration

    Un-comment the following line:

    export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
    
  3. Save the file.

  4. source ~/.zshrc

Give this one a try for other similar command not found errors.

Solution 4

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!

Solution 5

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.

Share:
156,738
Pattu
Author by

Pattu

Updated on July 09, 2022

Comments

  • Pattu
    Pattu almost 2 years

    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.

  • khalid khuz nain
    khalid khuz nain over 4 years
    You saved my life. thanks it work with source ~/.profile
  • compuphys
    compuphys about 4 years
    How is this the accepted answer? Sourcing bash_profile in .zshrc is a short term fix and may cause problems later. Bash and zsh are completely different shells with their own set of configuration files. See the zsh intro page for more info.
  • compuphys
    compuphys about 4 years
    This works but sourcing bash_profile in .zshrc is a short term fix and may cause problems later. Bash and zsh are completely different shells with their own set of configuration files. See the zsh intro page for more info.
  • Shamendra
    Shamendra about 3 years
    Now you will get the .zshrc.pre-oh-my-zsh file which includes all of your previous exports before oh-my-zsh installed will save in that file. So you can grab them from there and include in your newly overwritten .zhrc file will enable the commands back for you. Enjoy!
  • Tarnished-Coder
    Tarnished-Coder almost 3 years
    @compuphys what answer would you suggest then? I'm curious. From what I can see once bash_profile is sourced in .zshrc, all the paths available now in zshrc and in the future the user will only be using zsh to install any tools they want to. I'm not sure if I see an issue here nor do I see you long term solution.
  • tikej
    tikej over 2 years
    doesn't fix anything actually, no library still, and no bash_profile
  • Herii
    Herii over 2 years
    Thanks. It worked but I was a little bit confused by the format you used for the steps, I think it would be a better idea not to mark steps as code because it Is confusing.