一,maven官网:
http://maven.apache.org/
下载页面:
https://maven.apache.org/download.cgi
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,下载maven:
1,选择 apache-maven-3.8.2-bin.tar.gz 版本下载,如图:
复制链接
2,从命令行下载:
root@lhdpc:/usr/local/source# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz
三,安装maven:
1,解压:
root@lhdpc:/usr/local/source# tar -zxvf apache-maven-3.8.2-bin.tar.gz
2,移动到安装目录:
root@lhdpc:/usr/local/source# mv apache-maven-3.8.2 /usr/local/soft/
3,配置环境变量:
root@lhdpc:/usr/local/source# vi /etc/profile
在文件末尾处添加以下两行:
export MAVEN_HOME=/usr/local/soft/apache-maven-3.8.2 export PATH=$PATH:$MAVEN_HOME/bin
使变量生效:
root@lhdpc:/usr/local/source# source /etc/profile
四,查看安装效果:
root@lhdpc:/usr/local/source# mvn --version Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f) Maven home: /usr/local/soft/apache-maven-3.8.2 Java version: 16.0.2, vendor: Oracle Corporation, runtime: /usr/local/soft/jdk-16.0.2 Default locale: zh_CN, platform encoding: UTF-8 OS name: "linux", version: "5.11.0-31-generic", arch: "amd64", family: "unix"
五,配置本地仓库的路径
1,创建maven的仓库存储目录:
root@lhdpc:/usr/local/source# mkdir -p /data/maven/repository root@lhdpc:/usr/local/source# chmod 777 /data/maven/repository
2,编辑maven的配置文件
root@lhdpc:/usr/local/source# vi /usr/local/soft/apache-maven-3.8.2/conf/settings.xml
增加一行:
<localRepository>/data/maven/repository</localRepository>
效果如下:
3,检查是否生效:
root@lhdpc:/usr/local/source# mvn -X | grep 'local repository' [DEBUG] Using local repository at /data/maven/repository
可见已生效
六,配置使用阿里云的maven仓库镜像
1,阿里云云效 Maven的使用指南
https://developer.aliyun.com/mvn/guide
2,编辑maven配置文件
root@lhdpc:/usr/local/source# vi /usr/local/soft/apache-maven-3.8.2/conf/settings.xml
在<mirrors></mirrors>添加如下内容:
<mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror>
效果如图:
3,检查是否生效:
root@lhdpc:/usr/local/source# mvn -X | grep mirror
[DEBUG] Using mirror aliyunmaven (https://maven.aliyun.com/repository/public) for central (https://repo.maven.apache.org/maven2).
七,查看java版本
root@lhdpc:/usr/local/source# java --version java 16.0.2 2021-07-20 Java(TM) SE Runtime Environment (build 16.0.2+7-67) Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
八,查看linux版本
root@lhdpc:/usr/local/source# more /etc/os-release NAME="Ubuntu" VERSION="21.04 (Hirsute Hippo)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 21.04" VERSION_ID="21.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=hirsute UBUNTU_CODENAME=hirsute