Command not found - Oh-My-Zsh
Asked Answered
I

23

68

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.

Ingesta answered 26/11, 2015 at 9:47 Comment(1)
export PATH=$PATH:$M2_HOME/bin. Notice the $ I added. Also, no need to export; export sets a flag in bash/zsh/etc., and it only needs to be set once.Handel
B
94

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...
.......
Beatrice answered 9/8, 2018 at 6:19 Comment(7)
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.Comfit
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!Ariadne
@Comfit 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.Sculptress
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.Philosophize
add what? this is a partial answer.Lananna
@Comfit Some software, e.g. Homebrew, e.g.2. PhantomJS, give instructions for setting the path by adding an "export PATH" command (or similar) to your .bash_profile/.zprofile (depending on macos version). Thus this answer lets the user follow such instructions without having to mess about deciding if it belongs somewhere else or not.Arthritis
Note that Apple changed the default shell to zsh since Catalina, thus the profile file changed from .bash_profile to .zprofile.Arthritis
D
61

Just add:

source ~/.bash_profile

to .zshrc

Doak answered 12/9, 2017 at 15:2 Comment(3)
You saved my life. thanks it work with source ~/.profileCinch
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.Comfit
doesn't fix anything actually, no library still, and no bash_profileSpindell
R
32

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.

Rycca answered 11/7, 2016 at 16:53 Comment(0)
G
21

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!

Galton answered 27/10, 2020 at 13:42 Comment(0)
Q
13

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

Quadriplegic answered 1/6, 2022 at 10:38 Comment(1)
this. you need 'brew install maven' when continue a java proj on a new deviceHemisphere
L
8

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"
Lyford answered 25/11, 2021 at 4:38 Comment(1)
Thankyou. I had installed and moved to /opt correctly. But this additional config was remaining. It perfectly worked. I'm using mac m1, maven 3.8.6Bleb
F
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.

Fredric answered 28/7, 2019 at 18:37 Comment(0)
E
4
  • 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.
Elaineelam answered 28/11, 2015 at 6:20 Comment(0)
C
4

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

brew install maven
Cat answered 8/6, 2022 at 15:22 Comment(0)
D
3

I faced the exact same issue, this is what worked for me:

  1. sudo nano ~/.zshrc

  2. add this:

    export PATH=your maven path/apache-maven-3.6.3/bin:/usr/bin:/bin:/usr/sbin:/sbin
    
  3. Ctrl+X, select "Y", Press Enter

  4. source ~/.zshrc

  5. Validate: mvn -version

Draff answered 4/2, 2021 at 16:37 Comment(0)
E
2

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
Eustache answered 11/10, 2021 at 18:46 Comment(0)
M
2

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!

Maitilde answered 23/1, 2023 at 11:10 Comment(0)
C
1
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.

Cora answered 29/3, 2019 at 19:44 Comment(0)
N
1

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

Nerva answered 31/12, 2020 at 4:50 Comment(0)
B
0

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
Bithia answered 21/6, 2017 at 11:40 Comment(0)
E
0

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

Esse answered 3/9, 2020 at 12:10 Comment(0)
M
0

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

  1. .zshrc before change: export MAVEN_HOME=home/user/Tools/apache-maven-3.6.3 export PATH=$MAVEN_HOME/bin:$PATH
  2. good to verify if maven path exists. In my case it was error using command below ls $MAVEN_HOME
  3. .zshrc after fix one line export MAVEN_HOME=/home/user/Tools/apache-maven-3.6.3 export PATH=$MAVEN_HOME/bin:$PATH
  4. reload .zhsrc source .zshrc
  5. mvn command found
Mcshane answered 22/2, 2021 at 20:22 Comment(0)
A
0

If you are running Catalina you will face this problem often.

  1. Open your terminal
  2. Just copy all your Path variables and create a .zshrc file (touch .zshrc)
  3. open it (open ~/.zshrc) and paste them there,
  4. save and refresh your .zsrhc file ( source ~/.zshrc).

I found this Video very helpful to solve related problems.

Arbiter answered 12/4, 2021 at 15:0 Comment(0)
U
0

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

Unfurl answered 3/2, 2022 at 15:40 Comment(0)
C
0

If you want to configure intelliJ terminal with a custom Terminal or if you want fix "command not found", follow these steps:

  1. Click > File
  2. Click > Settings
  3. Click > Tools
  4. Click > Terminal
  5. 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"

  1. Click > Apply
  2. Click > Ok

I used git bash but technically it should work with every terminal. Do not forget to add --login after the *.exe

Carriecarrier answered 26/7, 2022 at 12:17 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Garbage
L
0

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

Lagoon answered 15/8, 2022 at 13:31 Comment(0)
L
-2

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
Locarno answered 26/4, 2020 at 5:5 Comment(0)
L
-2

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

Letterperfect answered 3/7, 2020 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.