I had maven and maven2 installed. I took it down with the command sudo apt-get remove maven*
- downloaded from off.site latest version of apache-maven-3.3.9-bin.zip
- unpacked the archive in /opt/maven
- renamed apache-maven-3.3.9 to apache_maven_3.3.9 now in the specified directory there are two apache_maven_3.3.9 directories apache-maven-3.3.9-bin.tar.gz
- set the environment variable M2_HOME " export M2_HOME=/opt/maven " to the /etc/profile file
- set the PATH export PATH=$PATH:$M2_HOME/bin environment variable export PATH=$PATH:$M2_HOME/bin to the /etc/profile file
after checking the installation is correct, typing mvn -version on the command line

The 'mvn' application can be found in the following packages:
* maven
* maven2
Try: sudo apt-get install <selected package>

I chose maven2
After installation, I check what happened. answer

Apache Maven 2.2.1 (rdebian-14)
Java version: 1.8.0-ea
Java home: / usr / lib / jvm / java-8-oracle / jre
Default locale: en_UA, platform encoding: UTF-8
OS name: "linux" version: "3.16.0-51-generic" arch: "amd64" Family: "unix"

What have I done wrong? Why is the version installed 2.2.1 and not the one that I registered 3.3.9 ?

    1 answer 1

    What version is in the repository, and that is installed. Manual unpacking does not affect this.

    As you can see, maven installed in the /opt/maven/apache-maven-3.3.9 folder, and the /opt/maven/bin directory is specified in $PATH . Naturally, the system can not find it. To fix the situation, either unpack the contents of the archive so that the bin directory is in the /opt/maven folder, or type

     export M2_HOME=/opt/maven/apache-maven-3.3.9 

    To make it easy to change versions, I would recommend installing maven in the /opt/apache-maven-3.3.9 directory and creating a symbolic link /opt/maven to this directory:

     ln -s /opt/apache-maven-3.3.9 /opt/maven 

    This eliminates the need to write new values ​​in $PATH and $M2_HOME . To change the version, it will be enough just to delete the link and create a new one pointing to another directory.

    Now make the maven "visible" in the system. If this is not done, she will declare that the required program has not been found and offer to install it from the repository. In the /etc/profile.d directory we create a file with the name, for example, maven.sh with the following contents:

     export M2_HOME=/opt/maven export PATH=$PATH:$M2_HOME/bin 

    Reboot the system or relogin (it is better to reboot all the same ...). Done! Maven works.

    • did not help. deleted the maven folder completely and unpacked it again in /opt , changed the dash to underscore /opt/maven /opt/apache_maven_3.3.9 and created the /opt/maven link to this directory. anyway the old version of Apache Maven 2.2.1 (rdebian-14) - makson
    • Remove the version from the repository: sudo apt-get purge maven* . - user194374
    • did everything again. deleted from repository. writes Приложение 'mvn' может быть найдено в следующих пакетах: * maven * maven2 Попробуйте: sudo apt-get install <выбранный пакет> - makson
    • /opt//apache_maven_3.3.9 - the folder where the maven is lying export M2_HOME=/opt/maven export PATH=$PATH:$M2_HOME/bin way about adding M2_HOME and PATH - should I add them to any place in the file? - makson
    • @makson Updated the answer. - user194374