注意:最初发布时我试图安装maven2。由于主要答案是maven3,我更新了标题。问题的其余部分仍然是最初发布的。
我正在尝试使用命令
在redhat linux机器上安装maven2 yum install maven2
但是yum似乎无法找到maven2。
No package maven2 available
我遇到过关于此主题的其他帖子,但以下帖子的回答建议添加回购。我添加了所述回购,但添加后会遇到错误。
How to install Maven into Red Hat Enterprise Linux 6?
我只能通过命令行访问此框,因此我很难从他们的网站上下载maven。
答案 0 :(得分:87)
转到mirror.olnevhost.net/pub/apache/maven/binaries/并查看最新的tar.gz文件
假设它是例如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
然后继续安装。
更新:添加完整说明(从下面的评论中复制)
运行以下内容以解压缩tar:
tar xvf apache-maven-3.2.1-bin.tar.gz
接下来添加env varibles,例如
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.1
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
验证
mvn -version
答案 1 :(得分:5)
我制作了以下剧本:
#!/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
答案 2 :(得分:2)
在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 sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
-> sudo yum install -y apache-maven
-> mvn --version
输出类似于
Apache Maven 3.5.2(138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)Maven主页:/ usr / share / apache-maven Java 版本:1.8.0_171,供应商:Oracle Corporation Java主页: /usr/lib/jvm/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”,拱门:“ amd64”,家族:“ unix”
*如果抛出的错误与Java有关,请按照以下步骤更新Java 8 *
在Amazon Linux / redhat中安装Java 8
-> yum search java | grep openjdk
-> yum install java-1.8.0-openjdk-headless.x86_64
-> yum install java-1.8.0-openjdk-devel.x86_64
-> update-alternatives --config java #pick java 1.8
并按1
-> update-alternatives --config javac #pick java 1.8
并按2
谢谢
答案 3 :(得分:1)
与其他人说的相似,但是逐步使用“〜/ .bash_profile”(适合初学者):
cd ~ && mkdir installed-packages
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
tar -xvf apache-maven-3.5.0-bin.tar.gz
ln -s ~/installed-packages/apache-maven-3.5.0 /usr/local/apache-maven
~/.bash_profile
(这是通常存储环境变量的地方):
vi ~/.bash_profile
MVN_HOME=/usr/local/apache-maven
(在定义PATH变量之前执行此操作)
vi
工具的人:按i
键启用插入模式):$MVN_HOME:$MVN_HOME/bin
vi
工具的人:按esc
键退出插入模式,:wq!
保存并退出文件)source ~/.bash_profile
mvn --help
答案 4 :(得分:0)
有时,即使正确设置了M2_HOME和PATH参数,你也可能会在主题“java.lang.NoClassDefFoundError:org / codehaus / classworlds / Launcher”中出现“Exception in thread”。
此异常是因为您的JDK / Java版本需要更新/安装。