Setting permanent environment variable [duplicate]

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/

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