Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install maven on redhat linux

Note: When originally posted I was trying to install maven2. Since the main answer is for maven3 I have updated the title. The rest of the question remains as it was originally posted.

I'm trying to install maven2 on a redhat linux box using the command

 yum install maven2 

but yum doesn't seem to be able to find maven2.

No package maven2 available 

I've run across other posts about this topic, but the answer to the following post suggests to add repos. I add said repos, but run into errors after adding them.

How to install Maven into Red Hat Enterprise Linux 6?

I can only access this box via command line so simply downloading maven from their website is difficult for me.

like image 634
OrwellHindenberg Avatar asked Aug 22 '12 15:08

OrwellHindenberg


People also ask

How do I run Maven on Linux?

Installing Maven on Linux/Unix Visit the Apache Maven site, download the Maven binary tar. gz file of the latest version, and ​extract the archive to the folder you want to use Maven in. Open the terminal and run the following commands to set the environment variables; for example, if apache-maven-3.3. 9-bin.


2 Answers

Go to mirror.olnevhost.net/pub/apache/maven/binaries/ and check what is the latest tar.gz file

Supposing it is e.g. apache-maven-3.2.1-bin.tar.gz, from the command line; you should be able to simply do:

wget http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.1-bin.tar.gz 

And then proceed to install it.

UPDATE: Adding complete instructions (copied from the comment below)

  1. Run command above from the dir you want to extract maven to (e.g. /usr/local/apache-maven)
  2. run the following to extract the tar:

    tar xvf apache-maven-3.2.1-bin.tar.gz 
  3. Next add the env varibles such as

    export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.1

    export M2=$M2_HOME/bin

    export PATH=$M2:$PATH

  4. Verify

    mvn -version 
like image 164
Icarus Avatar answered Sep 20 '22 08:09

Icarus


I made the following script:

#!/bin/bash  # Target installation location MAVEN_HOME="/your/path/here"  # Link to binary tar.gz archive # See https://maven.apache.org/download.cgi?html_a_name#Files MAVEN_BINARY_TAR_GZ_ARCHIVE="http://www.trieuvan.com/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz"  # Configuration parameters used to start up the JVM running Maven, i.e. "-Xms256m -Xmx512m" # See https://maven.apache.org/configure.html MAVEN_OPTS="" # Optional (not needed)  if [[ ! -d $MAVEN_HOME ]]; then   # Create nonexistent subdirectories recursively   mkdir -p $MAVEN_HOME    # Curl location of tar.gz archive & extract without first directory   curl -L $MAVEN_BINARY_TAR_GZ_ARCHIVE | tar -xzf - -C $MAVEN_HOME --strip 1    # Creating a symbolic/soft link to Maven in the primary directory of executable commands on the system   ln -s $MAVEN_HOME/bin/mvn /usr/bin/mvn    # Permanently set environmental variable (if not null)   if [[ -n $MAVEN_OPTS ]]; then     echo "export MAVEN_OPTS=$MAVEN_OPTS" >> ~/.bashrc   fi    # Using MAVEN_HOME, MVN_HOME, or M2 as your env var is irrelevant, what counts   # is your $PATH environment.   # See http://stackoverflow.com/questions/26609922/maven-home-mvn-home-or-m2-home   echo "export PATH=$MAVEN_HOME/bin:$PATH" >> ~/.bashrc else   # Do nothing if target installation directory already exists   echo "'$MAVEN_HOME' already exists, please uninstall existing maven first." fi 
like image 21
ecwpz91 Avatar answered Sep 22 '22 08:09

ecwpz91