How to save environment variable on my Ubuntu Linux system

1

I am using Maven to the build process of my Java project.

To launch the mvn command in any position within the shell I am using the following command to declare the environment variable in this way:

export MAVEN_HOME=/home/andrea/SpringSource/apache-maven-3.0.4

export PATH=$PATH:$MAVEN_HOME/bin

The problem is that if I close my shell, when I open it again I have to give again the previous commands...how can I solve this problem and "save" the environment variable on my system?

Thank you

Andrea

AndreaNobili

Posted 2012-11-29T11:28:13.960

Reputation: 5 433

Answers

2

You should save these commands as lines in your ~/.bashrc file. That way, these commands are applied/run each time you start a new instance of bash, i.e. each time you log in.

Otherwise:

  • To make the variables system-wide, disregarding which shell you use, assign the variables in /etc/environment (as described here) (alternatively in /etc/profiles).
  • To make the variables system-wide for bash (for all users using bash), place the lines in the file /etc/bash.bashrc (alternatively in /etc/bashrc on some other OSes than Ubuntu)

poplitea

Posted 2012-11-29T11:28:13.960

Reputation: 756

Note, you cannot use variables in /etc/environment, so $MAVEN_HOME, $PATH will not work. Only static values. – wisbucky – 2019-04-18T16:51:34.250