ChatGPT解决这个技术问题 Extra ChatGPT

How do I install Maven with Yum?

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.


j
jewelsea

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

Run the wget command from the dir you want to extract maven too. run the following to extract the tar, tar xvf apache-maven-3.0.5-bin.tar.gz move maven to /usr/local/apache-maven mv apache-maven-3.0.5 /usr/local/apache-maven 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 Execute these commands source ~/.bashrc

6:. Verify everything is working with the following command

    mvn -version

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 :)
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 probably because there are those that consider Maven anathema
just replace the path you pass to wget with one you get from maven.apache.org/download.cgi
@Ali Does Apache provide a way to use their domain name rather than the mirrors domain name ?
T
TTaaLL

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.


As described in this forum, 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.
Even replacing epel-$releasever with epel-6 fails with 404: repos.fedorapeople.org/repos/dchen/apache-maven/epel-6/i386/…: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
it's possible to install a specific (e.g. 3.0.1) version with this approach?
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/
alternatives --config java
S
SergeyB

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.


This sounded like it would work perfectly except received this error: repos.fedorapeople.org/repos/dchen/apache-maven/epel-6/x86_64/…: [Errno 14] HTTPS Error 404 - Not Found Don't know if the repo is temporarily down or permanently down.
@advocate I just created another server instance and run the exact commands as described and worked like a charm. sorry for the late reply, but looks like it still working. cheers.
I guess @Kate means $releasever.
This worked for me without step 2, but it wants to isntall jdk 1.7 even though I already have a 1.8 installed
It installs Java 7 and set it as default, so it brokes the further process for me :(
宏杰李
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

J
Johan Vergeer

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

$ sudo yum install maven

is supported these days.


Works for me on Amazon Linux 2 (March 2019).
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...
thank you, this answer should go to top of the list
q
quickshiftin

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 ;)


I went with maven 3 for my purposes, but just as easy to package maven v2.
One other note, you'll have to logout / login for the /etc/profile.d/maven.sh script to take.
Nice solution, thanks. BTW. You can also type exec bash (assuming you are using bash).
k
klaustopher

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


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.
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
Question is about installing it with yum.
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.
/usr/bn or /usr/bin? What about other directories such as /usr/local?
j
jgp

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"

u
user7610

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

[...]

a silly gotcha is that maven is not maven executable, but rather mvn...
K
Kannan Ramamoorthy

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