如何使用 Yum 安装 Maven?

发布于 2024-12-06 08:17:31 字数 567 浏览 1 评论 0原文

我试图了解太多有关 yum 或 maven 的知识。我继承了这段代码,并且我不想在这个环境中花费更多的时间。

我有百胜。我的安装“有”(“也附加了”?“知道”?)两个存储库:Amazon 和 JPackage,我认为这是一种标准。 (实际上,每个存储库都包含两个子存储库,但我不认为这会导致问题。)

当我要求 yum 安装 maven2 时,它拒绝了,说它从未听说过 maven2。

当我要求 yum 安装 maven2 时忽略 Amazon,它确实这样做了,但它安装了相当旧的 Maven 2.0.9。我实际的 pom.xml 需要更高的版本。

当我 Google 搜索 Maven 存储库时,我得到的是 Maven 可以用来构建其他东西的存储库,而不是 Yum 可以用来安装 Maven 的存储库。 (我确实找到了一个包含让 Maven 构建 Yum 的东西的存储库。我认为 Google 在这一点上正在嘲笑我。)

因此,我需要的只是存储库文件,它指向包含我的任何内容的存储库。需要安装Maven 2.2.1。

如果没有这些节省劳力的设备,我可能可以完成一些工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

预谋 2024-12-13 08:17:32

我最近刚刚了解到一个名为 fpm 的便捷打包工具。偶然发现这个问题,我想我可以尝试一下。事实证明,在阅读@OrwellHindenberg 的回答后,使用 fpm 将 maven 打包成 RPM 是很容易的。

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

创建项目目录并布局包的目录结构

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

创建一个文件,我们将安装到/etc/profile.d/maven.sh,我们将其存储在新创建的etc/profile.d目录为maven.sh,包含以下内容

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

下载并解压最新的 Maven 中 最后在opt 目录中

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

,构建 RPM

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

现在你可以通过 rpm

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

和 viola

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

安装 Maven,虽然不完全是yum,但离家更近了;)

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

朦胧时间 2024-12-13 08:17:32

需要用yum安装吗?还有很多其他可能性:

  • http://maven.apache.org/download.html 并将其放入 /usr/bn
  • 如果您使用 Eclipse,您可以获得 m2eclipse 插件 (http://m2eclipse.sonatype.org/),它捆绑了一个版本的 maven

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
夢归不見 2024-12-13 08:17:32

这就是我在 Amazon/AWS EMR v5 上经历的事情。 (改编自之前的答案),拥有 MavenJava8

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

现在,如果你运行:

mvn -version

你应该得到:

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"

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"
牵强ㄟ 2024-12-13 08:17:32

自 2014 年中期以来,Maven 已针对 Fedora 进行了打包,因此现在非常简单。只需输入

sudo dnf install maven

Now test the Installation,只需在随机目录中运行 maven

mvn

就会失败,因为您没有指定目标,例如 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

[...]

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

[...]
零度℉ 2024-12-13 08:17:32

不仅仅是 mvn,对于任何 util,您都可以通过给出 yum whatprovides {command_name} 来了解自己

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

書生途 2024-12-13 08:17:31

伊卡洛斯为我回答了一个非常相似的问题。它不使用“yum”,但仍然应该适合您的目的。尝试一下,

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

基本上只需访问 maven 站点。找到你想要的maven版本。文件类型并使用上面 wget 语句的镜像。

之后的过程很简单,

  1. 从你想要解压maven的目录运行wget命令。
  2. 运行以下命令来提取 tar,

    tar xvf apache-maven-3.0.5-bin.tar.gz
    
  3. 将 maven 移动到 /usr/local/apache-maven

    mv apache-maven-3.0.5 /usr/local/apache-maven
    
  4. 接下来将环境变量添加到 ~/.bashrc 文件

    export M2_HOME=/usr/local/apache-maven
    导出M2=$M2_HOME/bin 
    导出路径=$M2:$PATH
    
  5. 执行这些命令

    source ~/.bashrc

6:。使用以下命令验证一切正常

    mvn -version

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
三生池水覆流年 2024-12-13 08:17:31

您可以将 maven 添加到 yum 库,如下所示:

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

现在您可以像这样安装 maven:

yum install apache-maven

一旦完成,将安装 maven 3 并且 mvn -version 将显示哪个版本你有 - 我有 3.2.1。

除了一个例外,这在 CentOS 6 上对我来说非常有效。它安装了 OpenJDK 1.6 并使其成为默认的 Java 版本,尽管我已经手动安装了 JDK 8(可能因为是我手动安装的)。要将其更改回来,请使用alternatives

alternatives --config java
alternatives --config javac

并选择正确的版本。

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.

为你鎻心 2024-12-13 08:17:31

为了将来的参考和简单起见,对于懒惰的人来说,他们不需要太多解释,只需运行并使其尽快工作:

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
mvn --version

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:

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
mvn --version
·深蓝 2024-12-13 08:17:31
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

对于 JVM 开发人员来说,这是一个 SDK 管理器,可提供您所需的所有工具。

https://sdkman.io /

安装sdkman:

yum install -y zip unzip

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

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

安装Maven:

sdk install maven
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
当梦初醒 2024-12-13 08:17:31

对于那些正在寻找 2018 年安装 Maven 方法的人来说:

$ sudo yum install maven

现在已经支持了。

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

$ sudo yum install maven

is supported these days.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文