yum安装maven过程记录

会有一股神秘感。 提交于 2020-03-16 20:01:15

某厂面试归来,发现自己落伍了!>>>

安装maven,环境虚拟机:

1.安装yum配置工具

$ yum install -y yum-utils

2.使用配置工具配置第三方epel源仓库

[root@ab0be27c0bd3 ~]# yum-config-manager --add-repo http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo


Traceback (most recent call last):
  File "/usr/bin/yum-config-manager", line 6, in <module>
    import yum
ImportError: No module named yum

执行这一步报错

Traceback (most recent call last):
  File "/usr/bin/yum-config-manager", line 6, in <module>
    import yum
ImportError: No module named yum

根据报错查看文件:

[root@ab0be27c0bd3 ~]# cat /usr/bin/yum-config-manager | head -n 10


#!/usr/bin/python -tt

import os, os.path
import sys
import re
import yum
sys.path.insert(0,'/usr/share/yum-cli')
from utils import YumUtilBase
import logging
import fnmatch

说是找不到yum模块,但是yum命令是可以正常使用,百度说是版本不匹配,yum使用python写的

查看python的版本

[root@ab0be27c0bd3 ~]# whereis python


python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/bin/python2.6 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python /usr/local/bin/python2.7 /usr/local/bin/python2.7-config /usr/local/lib/python2.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz
[root@ab0be27c0bd3 ~]#
[root@ab0be27c0bd3 ~]#
[root@ab0be27c0bd3 ~]# python -V
Python 2.7.9

可以看到有多个版本,使用中的是2.7.9

看一下 yum使用的版本

[root@ab0be27c0bd3 ~]# cat /usr/bin/yum


#!/usr/bin/python
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\

其实看不出来呀,再看下python的软连接:

[root@ab0be27c0bd3 ~]# ls -il /usr/bin | grep python
33555577 -rwxr-xr-x   1 root  root       11216 Dec  1  2015 abrt-action-analyze-python
34184332 lrwxrwxrwx   1 root  root          24 Jul 19  2019 python -> /usr/local/bin/python2.7
33827326 lrwxrwxrwx   1 root  root           9 Nov 22  2016 python2 -> python2.7
34184333 lrwxrwxrwx   1 root  root           7 Nov 22  2016 python2.6 -> python2
33827328 -rwxr-xr-x   1 root  root        7136 Nov 20  2015 python2.7
33827329 -rwxr-xr-x   1 root  root        1835 Nov 20  2015 python2.7-config
33827327 lrwxrwxrwx   1 root  root          16 Nov 22  2016 python2-config -> python2.7-config
33827325 lrwxrwxrwx   1 root  root          14 Nov 22  2016 python-config -> python2-config

其实有点没看懂这个,在我看来,python,python2,python2.6都是指向的是python2.7呀,那/usr/bin/yum和/usr/bin/yum-config-manager使用的版本应该一样的,但是结果就是报错,根据百度的把/usr/bin/yum-config-manager改成2.6

#!/usr/bin/python2.6 -tt

再执行命令,居然就不报那个错了+_+||,但是报下面的错:

Loaded plugins: fastestmirror, langpacks
adding repo from: http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo
grabbing file http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo to /etc/yum.repos.d/epel-apache-maven.repo
Could not fetch/save url http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo to file /etc/yum.repos.d/epel-apache-maven.repo: [Errno 14] curl#7 - "Failed connect to repos.fedorapeople.org:80; Connection refused"

因为我是在虚拟机上执行的,无法连接外网,所以需要开通外网(直接用的公司的工具,点下开通外网就行,具体怎么给虚拟机开通外网还没研究) ,开通外网后这步命令执行成功。

3.启用仓库

[root@ab0be27c0bd3 ~]# yum-config-manager --enable epel-apache-maven


Loaded plugins: fastestmirror, langpacks
============================================================================== repo: epel-apache-maven ==============================================================================
[epel-apache-maven]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-7/x86_64/

4.安装maven

[root@ab0be27c0bd3 ~]# yum install -y apache-maven

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.9 (default, Jul 19 2019, 14:45:37)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

??版本又不匹配?

然后把/usr/bin/yum也改成2.6

#!/usr/bin/python2.6
import sys
try:

不说版本不一致了,然鹅

[root@ab0be27c0bd3 ~]# yum install -y apache-maven

▽
Loaded plugins: fastestmirror, langpacks

▽
#! /usr/bin/python-ext-down
base                                                                                                                                                          | 3.6 kB  00:00:00
didi_jenkins_enable                                                                                                                                           | 1.5 kB  00:00:00
didi_op_toa_enable                                                                                                                                            | 1.5 kB  00:00:00
didi_txjenkins_enable                                                                                                                                         | 1.5 kB  00:00:00
epel                                                                                                                                                          | 5.3 kB  00:00:00
epel-apache-maven                                                                                                                                             | 3.3 kB  00:00:00
extras                                                                                                                                                        | 3.4 kB  00:00:00
updates                                                                                                                                                       | 3.4 kB  00:00:00
Traceback (most recent call last):
  File "/usr/libexec/urlgrabber-ext-down", line 22, in <module>
    from urlgrabber.grabber import \
ImportError: No module named urlgrabber.grabber


Exiting on user cancel

然后vim /usr/libexec/urlgrabber-ext-down

把头改成

#! /usr/bin/python-ext-down

再执行打印了一堆东西,也不知道成功没,使用命令mvn -version,说命令找不到

最后换了种方式:

//下载
# wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
//解压
# tar -zxvf apache-maven-3.5.4-bin.tar.gz
//配置maven
# vim /etc/profile
export MAVEN_HOME=~/apache-maven-3.5.4 
export PATH=$MAVEN_HOME/bin:$PATH
//使配置生效
# source /etc/profile

黑人问号,反正就用这个maven

终于搞好了maven,接着就是构建启动项目,构建项目的时候又报错:

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

百度解决方法,去到我maven安装目录下修改启动文件:

# vim ~/apache-maven-3.5.4/bin/mvn

//加上
JAVA_HOME=`/usr/local/jdk1.8.0_65`

 再build不报那个错了

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!