In my experience, please check your /bin/mvn which is a POSIX shell script. In the script, it firstly finds maven related env from for e.g. /etc/mavenrc or $HOME/.mavenrc. In my case, in /etc/mavenrc, the M2_HOME env variable was set to the one I had removed, then after I set M2_HOME to the new maven installation, "mvn -v" worked.