如何在redhat linux上安装maven

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12076326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:08:05  来源:igfitidea点击:

How to install maven on redhat linux

linuxmavenredhatyum

提问by OrwellHindenberg

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.

注意:最初发布时,我试图安装 maven2。由于主要答案是针对 maven3,因此我更新了标题。问题的其余部分仍然是最初发布的。

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

我正在尝试使用以下命令在 redhat linux 机器上安装 maven2

 yum install maven2

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

但是 yum 似乎无法找到 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.

我已经看过有关此主题的其他帖子,但以下帖子的答案建议添加 repos。我添加了上述 repos,但添加后遇到错误。

How to install Maven into Red Hat Enterprise Linux 6?

如何将 Maven 安装到 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.

我只能通过命令行访问这个框,所以简单地从他们的网站下载 maven 对我来说很困难。

采纳答案by Icarus

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

转到mirror.olnevhost.net/pub/apache/maven/binaries/并检查最新的 tar.gz 文件是什么

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

假设它是例如 apache-maven-3.2.1-bin.tar.gz,来自命令行;你应该能够简单地做:

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
    
  1. 从要将 maven 提取到的目录中运行上面的命令(例如 /usr/local/apache-maven)
  2. 运行以下命令来提取 tar:

    tar xvf apache-maven-3.2.1-bin.tar.gz
    
  3. 接下来添加环境变量,例如

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

    export M2=$M2_HOME/bin

    export PATH=$M2:$PATH

  4. 核实

    mvn -version
    

回答by Om Sao

Sometimes you may get "Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/classworlds/Launcher" even after setting M2_HOME and PATH parameters correctly.

有时,即使在正确设置 M2_HOME 和 PATH 参数后,您也可能会收到“线程“main”java.lang.NoClassDefFoundError: org/codehaus/classworlds/Launcher 中的异常。

This exception is because your JDK/Java version need to be updated/installed.

此异常是因为您的 JDK/Java 版本需要更新/安装。

回答by ecwpz91

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

回答by Antony Fuentes Artavia

Pretty much what others said, but using "~/.bash_profile" and step by step (for beginners):

几乎其他人所说的,但使用“〜/ .bash_profile”并逐步(对于初学者):

  1. Move to home folder and create a new folder for maven artifacts:
    • cd ~ && mkdir installed-packages
  2. Go to https://maven.apache.org/download.cgiand wget the latest artifact:
    • If you don't have wget installed: sudo yum install -y wget
    • cd ~/installed-packages
    • wget http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
  3. Uncompress the downloaded file:
    • tar -xvf apache-maven-3.5.0-bin.tar.gz
  4. Create a symbolic link of the uncompressed file:
    • ln -s ~/installed-packages/apache-maven-3.5.0 /usr/local/apache-maven
  5. Edit ~/.bash_profile(This is where environment variables are commonly stored):
    • vi ~/.bash_profile
    • Add the variable: MVN_HOME=/usr/local/apache-maven(do this before PATH variable is defined)
      • (For those who don't know vitool: Press ikey to enable insert mode)
    • Go to the end of the line where PATH variable is defined and append the following: :$MVN_HOME:$MVN_HOME/bin
    • Save changes
      • (For those who don't know vitool: Press esckey to exit insert mode and :wq!to save and quit file)
  6. Reload environment variables:
    • source ~/.bash_profile
  7. Confirm that maven command now works properly:
    • mvn --help
  1. 移动到主文件夹并为 Maven 工件创建一个新文件夹:
    • cd ~ && mkdir installed-packages
  2. 转到https://maven.apache.org/download.cgi并 wget 最新的工件:
    • 如果你没有安装 wget: sudo yum install -y wget
    • cd ~/installed-packages
    • wget http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
  3. 解压下载的文件:
    • tar -xvf apache-maven-3.5.0-bin.tar.gz
  4. 创建未压缩文件的符号链接:
    • ln -s ~/installed-packages/apache-maven-3.5.0 /usr/local/apache-maven
  5. 编辑~/.bash_profile(这是环境变量通常存储的地方):
    • vi ~/.bash_profile
    • 添加变量:(MVN_HOME=/usr/local/apache-maven在定义 PATH 变量之前执行此操作)
      • (不知道vi刀具的人:按i键启用插入模式)
    • 转到定义 PATH 变量的行的末尾并附加以下内容: :$MVN_HOME:$MVN_HOME/bin
    • 保存更改
      • (不知道vi工具的人:按esc键退出插入模式和:wq!保存退出文件)
  6. 重新加载环境变量:
    • source ~/.bash_profile
  7. 确认 maven 命令现在可以正常工作:
    • mvn --help

回答by sachin_ur

Installing maven in Amazon Linux / redhat

在 Amazon Linux/redhat 中安装 maven

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

--> sudo wget http://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 sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo

-->sudo yum install -y apache-maven

-->sudo yum install -y apache-maven

--> mvn --version

--> mvn --version

Output looks like

输出看起来像



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.amzn2.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.14.47-64.38.amzn2.x86_64", arch: "amd64", family: "unix"

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z) Maven 主页:/usr/share/apache-maven Java 版本:1.8.0: vm/171 java-1.8.0-openjdk-1.8.0.171-8.b10.amzn2.x86_64/jre 默认语言环境:en_US,平台编码:UTF-8 操作系统名称:“linux”,版本:“4.14.47-64.38.amzn2. x86_64", arch: "amd64", family: "unix"

*If its thrown error related to java please follow the below step to update java 8 *

*如果抛出与java相关的错误,请按照以下步骤更新java 8 *

Installing java 8 in amazon linux/redhat

在 amazon linux/redhat 中安装 java 8

--> yum search java | grep openjdk

--> yum search java | grep openjdk

--> yum install java-1.8.0-openjdk-headless.x86_64

--> yum install java-1.8.0-openjdk-headless.x86_64

--> yum install java-1.8.0-openjdk-devel.x86_64

--> yum install java-1.8.0-openjdk-devel.x86_64

--> update-alternatives --config java #pick java 1.8and press 1

-->update-alternatives --config java #pick java 1.8然后按 1

--> update-alternatives --config javac #pick java 1.8and press 2

-->update-alternatives --config javac #pick java 1.8然后按 2

Thank You

谢谢你