6.2. Install Maven


Prerequisites

The following software must be installed:

  • An archiving tool for extracting the contents of compressed files.
  • Open JDK.

Procedure 6.2. Install Maven

  1. Download Maven.

    1. Enter http://maven.apache.org/download.cgi in the address bar of a browser.
    2. Download apache-maven-[latest-version] ZIP file and save it to your hard drive.
  2. Install and configure Maven.

    • On Red Hat Enterprise Linux

      1. Extract the ZIP archive to the directory where you wish to install Maven.
      2. Open your .bash_profile file in a terminal: vi ~/.bash_profile.
      3. Add the M2_HOME environment variable to the file:
        export M2_HOME=/path/to/your/maven
        Copy to Clipboard Toggle word wrap
      4. Also add the M2 environment variable to the file:
        export M2=$M2_HOME/bin
        Copy to Clipboard Toggle word wrap
      5. Add the M2 environment variable to the file:
        export PATH=$M2:$PATH
        Copy to Clipboard Toggle word wrap
      6. Make sure that JAVA_HOME is set to the location of your JDK. For example:
        export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64
        Copy to Clipboard Toggle word wrap
      7. Make sure that $JAVA_HOME/bin is in your PATH environment variable.
      8. Save the file and exit your text editor.
      9. Run this command to ensure the changes take effect: source ~/.bash_profile
      10. Run the following command to verify that Maven is installed successfully on your machine:
        mvn --version
        Copy to Clipboard Toggle word wrap
    • On Microsoft Windows

      1. Extract the ZIP archive to the directory where you wish to install Maven. The subdirectory apache-maven-[latest-version] is created from the archive.
      2. Press Start+Pause|Break. The System Properties dialog box is displayed.
      3. Click the Advanced tab and click Environment Variables.
      4. Under System Variables, select Path.
      5. Click Edit and add the two Maven paths using a semicolon to separate each entry.
        • Add the M2_HOME variable and set the path to C:\path\to\your\Maven.
        • Add the M2 variable and set the value to %M2_HOME%\bin.
      6. Update or create the Path environment variable:
        • Add the %M2% variable to allow Maven to be executed from the command line.
        • Add the variable %JAVA_HOME%\bin to set the path to the correct Java installation.
      7. Click OK to close all the dialog boxes including the System Properties dialog box.
      8. Open Windows command prompt and run the following command to verify that Maven is installed successfully on your machine:
        mvn --version
        Copy to Clipboard Toggle word wrap
Result

Maven is successfully installed and configured on your machine.

Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat