Warm tip: This article is reproduced from stackoverflow.com, please click
environment-variables maven zsh zshrc

Is there a robust way to set MAVEN_HOME in my ~/.zshrc without specifying the version number? (MacOS

发布于 2020-04-07 23:18:19

Context: I install maven with brew install maven

In my ~/.zshrc I have:

# Maven (mvn --version)
export MAVEN_HOME="$HOME/usr/local/Cellar/maven/3.6.3"
export PATH=$MAVEN_HOME/bin:$PATH

Is there a way to set my MAVEN_HOME in a way that allows me to not have to increment it when Maven is upgraded to 3.6.4?

It is somewhat tedious to have to go into my config file and update it every time I update Maven! :)

This would also help an onboarding/setup script that could download maven and programmatically set up a ~/.zshrc or ~/.bashrc config

Questioner
Mark Han
Viewed
82
Mark Han 2020-02-25 01:45

Per @chepner: /usr/local/bin/mvn is a symlink to the latest installed version when installed via homebrew.

I changed export MAVEN_HOME="/usr/local/Cellar/maven/3.6.3/mvn" to export MAVEN_HOME="/usr/local/bin/mvn" in my ~/.zshrc config and everything is good to go.