M2_HOME环境变量应如何配置?apt安装Maven后报错求助
Hey there! I see you're running into an issue with the Xtext Maven plugin complaining about a missing Maven home—let's get this sorted quickly.
First, Your M2_HOME Value
From your mvn --version output, the Maven home is clearly listed as /usr/share/maven—that's exactly what you need to set for M2_HOME.
How to Set M2_HOME
You have two options here: temporary (for your current terminal session only) or permanent (persists across all terminal sessions).
Temporary Setup (Current Session Only)
Run these commands in your terminal:
export M2_HOME=/usr/share/maven export PATH=$M2_HOME/bin:$PATH
This will immediately set the variable for your current session. You can verify it worked by running echo $M2_HOME—it should output /usr/share/maven.
Permanent Setup (All Sessions)
This depends on your shell:
For Bash users:
- Open your
~/.bashrcfile in a text editor (e.g.,nano ~/.bashrc). - Add these lines at the end of the file:
export M2_HOME=/usr/share/maven export PATH=$M2_HOME/bin:$PATH - Save the file and run
source ~/.bashrcto apply the changes right away.
- Open your
For Zsh users:
- Open
~/.zshrc(e.g.,nano ~/.zshrc). - Add the same two lines as above.
- Run
source ~/.zshrcto activate the changes.
- Open
Verify & Test
After setting the variable, confirm it's correctly set with:
echo $M2_HOME
Then re-run your Maven command:
mvn clean install
The Xtext plugin should now find the Maven home without issues.
Why This Happens
When you install Maven via apt, it doesn't automatically set the M2_HOME environment variable. The Xtext generator plugin explicitly checks for this variable (or the maven.home system property) to locate Maven's installation directory, hence the error you saw.
内容的提问来源于stack exchange,提问作者OrenIshShalom

