Maven – Fixing Environment Variable Issues in Terminal

bashcommand lineenvironment-variablesjavamaven-3

When I run echo $PATH and echo $JAVA_HOME command as a normal user, I get jdk path variables set. But when I run as a root user, the variables are not set there.

I copied maven binary folder to /opt then tried to install maven environment variable using command:

export PATH=/opt/apache-maven-3.3.9/bin:$PATH

When I run mvn -version in the current terminal I see maven variables set but when I run the command from a new terminal, it says maven is not installed.

And when I run mvn -version as a root user, from the current ternimal, it also gives shows maven not being installed.

Please help me to configure maven.

Thank you

Best Answer

Okay finally what I did was the same I did for installing java jdk environment i.e adding maven variables in /etc/profile. The steps are described below:-

  1. sudo pluma /etc/profile
  2. Add these commands at the end of the text file

    export M2_HOME=/opt/apache-maven-3.3.9

    export M2=$M2_HOME/bin

    export PATH=$M2:$PATH

  3. Reload profile by typing source /etc/profile in command line

  4. Restart the system

  5. Verify M2 by typing echo $M2 in command line

  6. Verify PATH by typing echo $PATH in command line. Check if there is maven directory in the PATH variable or not.
  7. Check maven version by typing mvn -version in command line