0

I want to set a permanent environment variable, I have used the .profile, .zshrc, .bash_profile, however, none have worked, after doing the command source .profile it works while I have the terminal open, but then when I close the terminal and reopen a new saves these variables.

This is how I save the variables in the files

export M2_HOME=/Applications/apache-maven-3.3.3
export PATH=$PATH:$M2_HOME/bin/
1

1 Answer 1

1

You can add to the end of the file ~/.zprofile the the following instructions :

# Setting PATH for Apache-maven-3.3.3
PATH="/Applications/apache-maven-3.3.3/bin:${PATH}"
export PATH

Then you close the terminal and reopen and verify

You can also replace by this :

# Setting PATH for Apache-maven-3.3.3
export M2_HOME=/Applications/apache-maven-3.3.3
PATH=$PATH:$M2_HOME/bin/
export PATH
1
  • The zsh manuals suggest that these should be in ~/.zshenv - however for interactive use in Terminal then it does not matter which startup file is used.
    – mmmmmm
    Nov 23, 2021 at 16:21

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