Reputation:
How to add Apache Maven to PATH on macOS Big Sur permanently ? I have downloaded and unzipped maven.
Upvotes: 0
Views: 5672
Reputation: 416
If you have downloaded maven from apache, and extracted the binary.zip, first you need to check your terminal type. To view it open your terminal and type,echo $SHELL
Then you will get your terminal type(zsh or bash).
If its bash open the .bash_profile
file by,
either open ~/.bash_profile
or vi ~/.bash_profile
.
Then add the apache maven path to it by first declaring the MAVEN_HOME
and M2_HOME
.
export MAVEN_HOME = '/{your-maven-location}/apache-maven-3.8.2/'
export M2_HOME = '/{your-maven-location}/apache-maven-3.8.2/'
Then add those to the PATH
variable by,
export PATH="$MAVEN_HOME/bin:$PATH"
export PATH="$M2_HOME/bin:$PATH"
After adding these lines save the .bash_profile.
Then in terminal type source ~/.bash_profile
to source the file.
Now, if you type echo $PATH
you can see the maven is added to your path.
And do the same thing for .zshrc file by opening it using open ~/.zshrc
or vi ~/.zshrc
.
You can either change .bash_profile or .zshrc file depending on the shell you have. But,I would recommend you to add the path variable to both files.
If you are having any sourcing issues, give file changing privileges by, sudo chown {your-username} ~/.bash_profile
or sudo chown {your-username} ~/.zshrc
.
You can find your username by ls -al /Users
Upvotes: 4