Learner
Learner

Reputation: 187

Environment variable getting unset everytime terminal session is closed

Iam new to linux , and trying to run some maven commands . My environment file content is follows -

JAVA_HOME=/usr/lib/jvm/java-openjdk
export JAVA_HOME
M2_HOME=/home/sam/Downloads/apache-maven-3.3.9
export M2_HOME
PATH=$PATH:$JAVA_HOME:$M2_HOME
export PATH

However whenever i run mvn related stuff once in a terminal and close it and reopen a new session , iam unable to run mvn commands , and i get "not a command " error .

Could any one help me how to rectify it so that i dont see this error again and again and the variables set permanently .

Upvotes: 1

Views: 2241

Answers (1)

tjs7706
tjs7706

Reputation: 85

You need to set path for java and maven.

You can do one thing add your path code

JAVA_HOME=/usr/lib/jvm/java-openjdk export JAVA_HOME M2_HOME=/home/sam/Downloads/apache-maven-3.3.9 export M2_HOME PATH=$PATH:$JAVA_HOME:$M2_HOME export PATH

into

~/.bashrc File.

This file is execute every time when you open your terminal. So once you write your export path text in this file it will remain set for all the time.

It is very simple to write your path in ~/.bashrc File.

  1. Open Your terminal
  2. vi ~/.bashrc
  3. .bashrc is Open now.
  4. Just press page-down button and go to the last line of the file.
  5. Copy your path code

    JAVA_HOME=/usr/lib/jvm/java-openjdk export JAVA_HOME
    M2_HOME=/home/sam/Downloads/apache-maven-3.3.9 export M2_HOME
    PATH=$PATH:$JAVA_HOME:$M2_HOME export PATH
  6. Press shift+i so you can add text in this file
  7. Now at the end of file just paste your code using ctrl+shift+v
  8. Now Save file, press Escape then shift+colon you can see colon (:) at end of terminal. Then Press wq so it will display like :wq
  9. Now press enter.

That's it.

Now close the terminal and reopen it. You can test your updated path is working or not using "mvn".

Upvotes: 1

Related Questions