0

I tried to install Maven on CentOS 7, but afterwards typing mvn -version in the terminal results in bash: mvn: command not found.... How can I fix this so that I can call maven from the CentOS 7 terminal?

The steps I took are from this tutorial, and they are also described explicitly and entirely as follows:

wget http://www.eng.lsu.edu/mirrors/apache/maven/maven-3/3.3.1/binaries/apache-maven-3.3.1-bin.zip

unzip apache-maven-3.3.1-bin.zip
mkdir /opt/maven
mv apache-maven-3.3.1/ /opt/maven
ln -s /opt/maven/bin/mvn /usr/bin/mvn
gedit /etc/profile.d/maven.sh
Add the following contents to /etc/profile.d/maven.sh :
    #!/bin/bash
    MAVEN_HOME=/opt/maven
    PATH=$MAVEN_HOME/bin:$PATH
    export PATH MAVEN_HOME
    export CLASSPATH=.

Save and close the file. Then: 
chmod +x /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh

Log out or reboot the computer. Then (with username and results shown this time):

[root@localhost ~]# mvn -version  
bash: mvn: command not found...  
[root@localhost ~]# mvn --version
bash: mvn: command not found...
[root@localhost ~]# echo $MAVEN_HOME  
/opt/maven  

Note that I did not install Ant. Also, the tomcat installation was done separately long ago.


EDIT


As per @MarkPlotnick's advice, I tried the following, with the following results:

[root@localhost ~]# mv /opt/maven /opt/maven.bak
[root@localhost ~]# mv /opt/maven.bak/apache-maven-3.3.1 /opt/maven
[root@localhost ~]# mvn -version
Apache Maven 3.3.1 (lotsnumbersandletters; 2015-03-13T13:10:27-07:00)
Maven home: /opt/maven
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /usr/java/jdk1.7.0_71/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "versionnumber", arch: "amd64", family: "unix"
2
  • Try mv /opt/maven /opt/maven.bak; mv /opt/maven.bak/apache-maven-3.3.1 /opt/maven and see if things work after that. Apr 21, 2015 at 1:40
  • @MarkPlotnick Please see my EDIT to my OP above. Does this mean it works now? If so, please feel free to submit it as an answer and I would be happy to accept it. I would be curious to hear your explanation of what happened. Thank you.
    – CodeMed
    Apr 21, 2015 at 2:20

1 Answer 1

2

The instructions you cited said to do this:

wget http://www.eng.lsu.edu/mirrors/apache/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.zip
unzip apache-maven-3.2.3-bin.zip
mv apache-maven-3.2.3/ /opt/maven

This will result in /opt/maven/bin, /opt/maven/lib, etc.

What you did was slightly different:

wget http://www.eng.lsu.edu/mirrors/apache/maven/maven-3/3.3.1/binaries/apache-maven-3.3.1-bin.zip
unzip apache-maven-3.3.1-bin.zip
mkdir /opt/maven
mv apache-maven-3.3.1/ /opt/maven

This resulted in /opt/maven/apache-maven-3.3.1/bin, /opt/maven/apache-maven-3.3.1/lib, etc.

When you do mv x /y/z, where x is a directory, three different things can happen:

  • if /y/z doesn't already exist, the entire tree rooted at x is moved to /y/z.
  • if /y/z already exists and is a directory, the tree is moved to /y/z/x.
  • if /y/z already exists and is not a directory, mv will output an error message and won't move anything.
0

You must log in to answer this question.

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