6

See the following mvn version. I'm wondering why "which" command does not give you the correct info.

LM-SIN-00676037:myproject haibliu$ mvn --version
Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800)
Maven home: /usr/share/maven
Java version: 1.6.0_37, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.8", arch: "x86_64", family: "mac"

LM-SIN-00676037:myproject haibliu$ which mvn
/usr/local/bin/mvn

LM-SIN-00676037:myproject haibliu$ /usr/local/bin/mvn --version
Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
Maven home: /usr/local/Cellar/maven/3.0.4/libexec
Java version: 1.6.0_37, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.8", arch: "x86_64", family: "mac"

Just to clarify: /usr/bin/mvn comes with my Max OS X, Mountain Lion. And I used Homebrew to install /usr/local/bin/mvn. After that, I changed the order of PATH in /etc/paths.

LM-SIN-00676037:myproject haibliu$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
LM-SIN-00676037:myproject haibliu$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

That's all I did. And I'm using bash shell.

  • 1
    That's odd. Perhaps some strange symlinking somewhere? Try running which -a and see what comes up. – robmathers Dec 5 '12 at 16:35
  • It returns 2 instances of mvn: "/usr/local/bin/mvn" and "/usr/bin/mvn". And "/usr/local/bin/mvn" comes first. – haibin Dec 5 '12 at 16:52
  • 3
    Did you install /usr/local/bin/mvn after running mvn in the current shell instance once? Bash tends to cache binary locations. – nohillside Dec 5 '12 at 16:59
  • The results of type mvn and pwd should let you know if the result is already hashed by the shell and if you happen to be in a directory where the path is choosing the local mvn over the one "which" finds first... If mvn is hashed, you simply have to re-start your shell or otherwise force a rehash. Feel free to write this up as an answer once you've sussed which of the above is causing your temporary grief with mvn. – bmike Dec 5 '12 at 16:59
7

which is an external program, which tries to determine how your shell will resolve a command from the existing $PATH, but it is possible for it to get it wrong.

If you're using bash as your shell, use the bash built-in command "type" to have the shell itself tell you how it will resolve that command:

$ which mvn
/usr/bin/mvn
$ type mvn
mvn is /usr/bin/mvn
$ type type
type is a shell builtin
$ type which
which is hashed (/usr/bin/which)

You can see here that in my environment that /usr/bin/which and the shell built-in type agree. In yours it seems they don't, though I am curious why they don't. Perhaps you have PATH changes that were not exported? Try "export PATH" and then "which mvn" again.

| improve this answer | |
  • 1
    "type mvn" returns "mvn is hashed (/usr/bin/mvn)" – haibin Dec 5 '12 at 16:58
  • 1
    So that confirms that bash is not choosing the path shown by /usr/bin/which. You don't the contents of your $PATH, so I can't say which mvn is first in your path. I tried an unexpected PATH and /usr/bin/which still got it right, so I'd guess that bash needs to rehash. As mentioned above, bash will cache locations. You can restart bash, but more simply I would force it to rehash with "hash -r". – Tim B Dec 5 '12 at 18:00
  • 1
    yes, it's the hash issue – haibin Dec 8 '12 at 14:21
0

what is in your $PATH? and more importantly, where did you install mvn? I remember when I tried to use MacPorts Phyton 2.7.3 I had to add /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python at the very beginning of the $PATH for which to give me the right python. To get the right path I had to add this in ~/.bash_profile:

source ~/.bashrc

# MacPorts Installer addition on 2010-03-17_at_21:13:03: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:$PATH

so, depending you will have to edit the path according to where mvn 3.0.3 is to have it fist.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .