You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M2_HOME环境变量应如何配置?apt安装Maven后报错求助

Fixing the "Maven home not found" Error for Xtext Plugin

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:

    1. Open your ~/.bashrc file in a text editor (e.g., nano ~/.bashrc).
    2. Add these lines at the end of the file:
      export M2_HOME=/usr/share/maven
      export PATH=$M2_HOME/bin:$PATH
      
    3. Save the file and run source ~/.bashrc to apply the changes right away.
  • For Zsh users:

    1. Open ~/.zshrc (e.g., nano ~/.zshrc).
    2. Add the same two lines as above.
    3. Run source ~/.zshrc to activate the changes.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 17:22:29