Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have downloaded the latest apache-maven3.zip file and extracted it to the folder: /home/gaurav/Java/maven3.

I don't know how to set the environmental variables for maven - such as PATH and M2_HOME.

I tried below things:

export M2_HOME=/home/gaurav/Java/maven3

export PATH= /home/gaurav/Java/maven3/bin:${PATH}

After setting that, I ran mvn --version and it is running correctly.

But when next time I start my machine, and type $M2_HOME, its not showing me the details of the path variables, neither mvn --version is getting executed.

Please help me to resolve this problem of permanently setting environment variables in Ubuntu.

share|improve this question
    
Take a look at This –  Mitch Mar 29 '13 at 7:08
add comment

2 Answers 2

Update: Eliah pointed out to me that if you are not dynamically building your environment variables, you should store them in /etc/environment. To set M2_HOME and add the bin directory to your PATH, you would modify your /etc/environment as follows. Make sure that you don't just copy/paste, because your /etc/environment file might have a different PATH variable than mine does.

M2_HOME="/home/gaurav/Java/maven3"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/gaurav/Java/maven3/bin"


Alternative (not as recommended) method: Like Mitch said, you'll need to edit a configuration file to permanently change your PATH. I chose to edit my /etc/profile configuration file, because it applies system-wide. To edit this file, run sudo nano /etc/profile Here's the relevant excerpt from my configuration file:

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

JAVA_HOME=/usr/lib/jvm/java-6-oracle/
export JAVA_HOME

M2_HOME=/usr/local/apache-maven/apache-maven-3.0.4
export M2_HOME
M2=$M2_HOME/bin
export M2

PATH=$PATH:$JAVA_HOME
PATH=$PATH:$M2
export PATH
share|improve this answer
    
Any reason not to just put the JAVA_HOME, M2_HOME, and M2 definitions in /etc/environment, instead? –  Eliah Kagan Apr 13 '13 at 2:39
    
That's definitely the semantically correct thing to do (because /etc/environment is the recommended place to store system-wide environment variables). But I just wanted to keep all of my environment variables in the same place. If there was a way I could dynamically build my PATH variable using only /etc/environment, I would immediately switch. –  connor.brinton Apr 13 '13 at 2:53
    
Since that's your motivation, you might want to add using /etc/environment as an alternative, considering that the goal of putting all your environment variable assignments in the same place is not necessarily this OP's goal or the goal of most other people who come by this question. Also, you may want to re-examine that goal: Most of the time, environment variables should be added at the user account level, to affect only a single user. (Then they can go in ~/.pam_environment or ~/.profile.) It's true that some environment variable assignments are dynamic and must be in scripts. –  Eliah Kagan Apr 13 '13 at 2:56
add comment

You have to add your PATH to /etc/bash.bashrc as root.

From root do these steps:

  1. sudo nano /etc/bash.bashrc
  2. At the end of the file, add the following line:

    PATH=/home/computer/application/bin:$PATH  
    

This is just a pseudo address. Change it according to the address that you want and add the :$PATH after it.

This is for Ubuntu.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.