Linux

it2025-04-25  4

1. 下载maven安装包,并上传到linux系统中。

maven 3.6.3 linux安装包

2. 解压

tar -xvf apache-maven-3.6.3-bin.tar.gz

3. 创建一个maven文件夹

mkdir maven

4. 将解压后的 apache-maven-3.6.3 文件夹,剪切到maven文件夹中,并使用pwd命令,找到apache-maven-3.6.3文件夹位置

/wangqinmin/maven/apache-maven-3.6.3 (这是我运行pwd的位置)

5. 在maven文件夹中,创建maven仓库文件夹

mkdir repository

 并pwd找到 创建的repository文件夹的位置 

/wangqinmin/maven/repository (这是我pwd查到的位置)

6. 配置环境变量

vim /etc/profile

7. 在最后一行,添加配置(注意这里面 /wangqinmin/maven/apache-maven-3.6.3 这个目录,是我上面的pwd命令拿到的位置,你们配置的时候,要改成自己的

export MAVEN_HOME=/wangqinmin/maven/apache-maven-3.6.3 export PATH=$PATH:$MAVEN_HOME/bin

8. 在apache-maven-3.6.3目录下,找到conf,再找到setting.xml文件

使用命令

vim setting.xml

找到以下位置:

<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> -->

并在这段 注释后添加:  (这里就是  添加上面创建的 repository文件夹位置

<localRepository>/wangqinmin/maven/repository</localRepository>

结果为:

| The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>/wangqinmin/maven/repository</localRepository>

9. 再找到 这段注释

<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> </mirrors>

再在  --> 后面添加 

<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>

结果为:

<!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>

10: 保存修改的文件  wq命令

11. 执行(刷新配置)

source /etc/profile

12. 运行 mvn -version 查看是否安装成功。

最新回复(0)