1

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

4
  • 1
    Possible duplicate of How do I set persistent environment variables for root?
    – kos
    Mar 19, 2016 at 9:43
  • The link which is provided as a duplicate post of is not what I am asking for. I want to set environment variables permanently not just in a terminal
    – viper
    Mar 19, 2016 at 10:29
  • If you set them in /etc/environment they'll be visible by all processes run after login (unless the process itself or one of its ancestors explicitly unsets them).
    – kos
    Mar 19, 2016 at 10:39
  • @pranishres: Then the keyword is "permanently". Take a look at this page. Mar 19, 2016 at 15:17

1 Answer 1

1

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

You must log in to answer this question.

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