141

I'm trying not to learn much about either yum or maven. I've inherited this code and I don't want to spend more time than I have to in this environment.

I've got yum. My installation "has" ("is attached too"? "knows about"?) two repos: the Amazon one and JPackage, which I understand is something of a standard. (Actually, each of those repositories consists of two sub-repositories, but I don't think that's causing the problem.)

When I asked yum to install maven2, it declined, saying it had never heard of maven2.

When I asked yum to install maven2 ignoring Amazon, it does so, but it installs Maven 2.0.9, which is fairly old. The actual pom.xml I have requires a higher version.

When I Google for Maven repositories I get repositories that Maven can use to build other things, not repositories that Yum can use to install Maven. (I did find a repository containing thing that let Maven build Yum. I think Google is mocking me at this point.)

So, all I need is the repo file that points to a repo that contains whatever I need to install Maven 2.2.1.

If it weren't for all these labor-saving devices, I could probably get some work done.

Malvolio
  • 38,966
  • 24
  • 87
  • 125

10 Answers10

221

Icarus answered a very similar question for me. Its not using "yum", but should still work for your purposes. Try,

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

basically just go to the maven site. Find the version of maven you want. The file type and use the mirror for the wget statement above.

Afterwards the process is easy

  1. Run the wget command from the dir you want to extract maven too.
  2. run the following to extract the tar,

    tar xvf apache-maven-3.0.5-bin.tar.gz
    
  3. move maven to /usr/local/apache-maven

    mv apache-maven-3.0.5  /usr/local/apache-maven
    
  4. Next add the env variables to your ~/.bashrc file

    export M2_HOME=/usr/local/apache-maven
    export M2=$M2_HOME/bin 
    export PATH=$M2:$PATH
    
  5. Execute these commands

    source ~/.bashrc

6:. Verify everything is working with the following command

    mvn -version
jewelsea
  • 130,119
  • 12
  • 333
  • 365
OrwellHindenberg
  • 4,731
  • 7
  • 34
  • 54
  • 1
    Thanks! the best maven i could get via `jpackage` was `maven.noarchtbd` which was `v1.1` or `maven2` which was `v2.0.4` ... your alternate instructions helped a lot to get me to maven v3 :) – pulkitsinghal Sep 17 '12 at 00:23
  • 54
    These instructions work. But why oh why can't they just put maven in the package repository with all the other packages so that people don't have to jump through these hoops? – aroth Nov 08 '12 at 06:30
  • 3
    @aroth probably because there are those that consider Maven anathema – Joseph Lust Nov 13 '13 at 03:45
  • 1
    just replace the path you pass to `wget` with one you get from http://maven.apache.org/download.cgi – Ali Mar 11 '14 at 15:18
  • @Ali Does Apache provide a way to use their domain name rather than the mirrors domain name ? – blong May 07 '14 at 14:19
  • @JosephLust those are the very most insane people walking on earth – Gewure May 27 '16 at 18:43
  • I found `export PATH=$M2:$PATH` to have corrupted my bash.. couldn't able to run any command like `ls` etc. so had to restore the ~/.bashrc and used `export PATH=$PATH:$M2:`[Note the change of $M2 after $PATH] to get the bash working. Hope this helps others, if needed. – Divs Mar 04 '18 at 13:58
  • On AWS Cloud9, this works too, except you have to add `sudo` in front of `mv apache-maven-3.0.5 /usr/local/apache-maven`. – Madoc Jun 15 '18 at 05:49
  • It looks like the host mirror for the wget is now down. This location worked for me: wget http://archive.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz – Ross A Dec 13 '20 at 20:50
116

You can add maven to the yum libraries like this:

wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo

Now you can install maven like this:

yum install apache-maven

Once done, maven 3 will be installed and mvn -version will show you which version you've got - I had 3.2.1.

This worked perfectly for me on CentOS 6 with one exception. It installed OpenJDK 1.6 and made it the default Java version, even though I'd already manually installed JDK 8 (possibly because I'd manually installed it). To change it back use alternatives:

alternatives --config java
alternatives --config javac

and choose the correct version.

TTaaLL
  • 107
  • 10
Phil Haigh
  • 4,322
  • 1
  • 23
  • 27
  • 9
    As described [in this forum](http://blog.gluster.org/2013/08/yum-install-maven-yes-you-can/), `epel-$releasever` in the downloaded `.repo` file needs to be replaced with `epel-6`, or else `yum install apache-maven` will fail with error 404. – O. R. Mapper Oct 06 '14 at 08:39
  • Even replacing epel-$releasever with epel-6 fails with 404: http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-6/i386/repodata/194b1dce25e9483ae3ce34f3e4f807770dd77705-primary.sqlite.bz2: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found" – lrkwz Mar 10 '15 at 06:42
  • 1
    it's possible to install a specific (e.g. 3.0.1) version with this approach? – bsferreira Apr 09 '15 at 11:27
  • I was able to get it working fine with this entry in the `/etc/yum.repos.d/epel-apache-maven.repo` repo file: `baseurl=https://repos.fedorapeople.org/repos/dchen/apache-maven/epel-6/$basearch/` – i_grok Dec 03 '15 at 16:46
  • `alternatives --config java` – vikingsteve Apr 18 '16 at 08:42
  • This one is missing [STEP 2 - replace `$releasever` with `6`](http://stackoverflow.com/a/34168861/432903) which is [described in another answer here](http://stackoverflow.com/a/34168861/432903) – prayagupd Apr 04 '17 at 07:21
  • I did as you said in CentOS 7, it works great, thanks. Just wondering that why this approach will change the jdk and how to prevent this problem? – frank Feb 24 '18 at 14:47
  • When I ran the maven installer there was no JDK or JRE installed via yum. So to all intents and purposes there was a missing dependency. I suspect it automatically installed the minimum version required as specified by the maven package. To stop it happening, install your JDK of preference first via yum. – Phil Haigh Jun 08 '18 at 09:00
  • `http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-latest/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found` – Chloe Jan 29 '19 at 20:04
66

For future reference and for simplicity sake for the lazy people out there that don't want much explanations but just run things and make it work asap:

1) sudo wget https://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo

2) sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo

3) sudo yum install -y apache-maven

4) mvn --version

Hope you enjoyed this copy & paste session.

SergeyB
  • 8,363
  • 3
  • 31
  • 45
20
yum install -y yum-utils

yum-config-manager --add-repo http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo

yum-config-manager --enable epel-apache-maven

yum install -y apache-maven

for JVM developer, this is a SDK manager for all the tool you need.

https://sdkman.io/

Install sdkman:

yum install -y zip unzip

curl -s "https://get.sdkman.io" | bash

source "$HOME/.sdkman/bin/sdkman-init.sh"

Install Maven:

sdk install maven
宏杰李
  • 10,658
  • 2
  • 21
  • 32
12

I've just learned of a handy packaging tool called fpm recently. Stumbling upon this question I thought I might give it a try. Turns out, after reading @OrwellHindenberg's answer, it's easy to package maven into an RPM with fpm.

yum install -y gcc make rpm-build ruby-devel rubygems
gem install fpm

create a project directory and layout the directory structure of the package

mkdir maven-build
cd maven-build
mkdir -p etc/profile.d opt

create a file that we'll install to /etc/profile.d/maven.sh, we'll store this under the newly created etc/profile.d directory as maven.sh, with the following contents

export M3_HOME=/opt/apache-maven-3.1.0
export M3=$M3_HOME/bin
export PATH=$M3:$PATH

download and unpack the latest maven in the opt directory

wget http://www.eng.lsu.edu/mirrors/apache/maven/maven-3/3.1.0/binaries/apache-maven-3.1.0-bin.tar.gz
tar -xzf apache-maven-3.1.0-bin.tar.gz -C opt

finally, build the RPM

fpm -n maven-3.1.0 -s dir -t rpm etc opt

Now you can install maven through rpm

$ rpm -Uvh maven-3.1.0-1.0-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:maven-3.1.0            ########################################### [100%]

and viola

$ which mvn
/opt/apache-maven-3.1.0/bin/mvn

not quite yum but closer to home ;)

quickshiftin
  • 55,146
  • 9
  • 56
  • 76
10

For those of you that are looking for a way to install Maven in 2018:

$ sudo yum install maven

is supported these days.

Johan Vergeer
  • 4,153
  • 7
  • 36
  • 81
  • Works for me on Amazon Linux 2 (March 2019). – ccleve Mar 08 '19 at 23:07
  • 1
    Yes, but I installed Java 11 on Amazon Linux 2, and then sudo yum install maven. It installed Java 8 and replaced my instance of 11. Somebody wasn't thinking... – ccleve Nov 21 '20 at 02:23
4

Do you need to install it with yum? There's plenty other possibilities:

  • Grab the binary from http://maven.apache.org/download.html and put it in your /usr/bn
  • If you are using Eclipse you can get the m2eclipse plugin (http://m2eclipse.sonatype.org/) which bundles a version of maven
klaustopher
  • 6,188
  • 1
  • 19
  • 23
  • 1
    Yeah, I'm going to do that in about the next 15 minutes if I cannot figure out a better way. The reason I'm hesitant is that Yum is actually a good product *if it knows about everything that's installed*. Otherwise, not so much. I'm sure Maven is also a good product, at doing something I don't need done, keeping library versions up to date. The system I'm tending to uses it as a build system, a task it is a little better at than a shell script and about a third as good as Make, circa 1989. Grrr. – Malvolio Sep 23 '11 at 17:56
  • Well, if they only maintained maven2 up to version 2.0.7 in the jPackage repository, then you can either deal with that version, install by hand or you could create an RPM from the sources at maven.apache.org and install this with yum. But you already stated that you don't want to spend more time then necessary with this, so I think option 1 would suit your situation the most – klaustopher Sep 23 '11 at 18:03
  • 2
    Question is about installing it with yum. – robermorales Apr 03 '12 at 12:12
  • 7
    Both of these answers do not answer the question. The real answer should be about some yum repo available that contains the maven3 (latest stable?) packages. – James Mills Dec 17 '12 at 00:49
  • 1
    `/usr/bn` or `/usr/bin`? What about other directories such as `/usr/local`? – Abdull Dec 10 '13 at 22:04
3

Maven is packaged for Fedora since mid 2014, so it is now pretty easy. Just type

sudo dnf install maven

Now test the installation, just run maven in a random directory

mvn

And it will fail, because you did not specify a goal, e.g. mvn package

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.102 s
[INFO] Finished at: 2017-11-14T13:45:00+01:00
[INFO] Final Memory: 8M/176M
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build

[...]
user7610
  • 17,196
  • 7
  • 97
  • 120
3

This is what I went through on Amazon/AWS EMR v5. (Adapted from the previous answers), to have Maven and Java8.

sudo wget https://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
sudo alternatives --config java

pick Java8

sudo alternatives --config javac

pick Java8

Now, if you run:

mvn -version

You should get:

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /usr/share/apache-maven
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.38.amzn1.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.14.47-56.37.amzn1.x86_64", arch: "amd64", family: “unix"
jgp
  • 1,495
  • 14
  • 34
1

Not just mvn, for any util, you can find out yourself by giving yum whatprovides {command_name}

Kannan Ramamoorthy
  • 3,077
  • 4
  • 35
  • 53