Maven collection: Linux/Windows environment installation configuration | Maven download and installation | Environment variable configuration

foreword

Maven is particularly important in daily development. For example, for the operation of RocketMQ , it is necessary to configure Maven in advance, and learn to install and configure Maven in different environments of Linux or Windows together

This article takes Maven3.8.6 as an example

Reminder: If you have multiple Linux versions installed on your local machine, it is recommended to perform this experiment on the higher version. The lower version of Linux / CentOS may cause some limitations for you in the use of some software!

Preparation

1. Enter the official download page and download different versions according to your own needs

Official download address: https://maven.apache.org/download.cgi  | Maven historical version download , entry 1 , entry 2 .

Note: select maven-3.8.6-bin.zip  for windows version and maven-3.8.6-bin.tar.gz for Linux version

1. Linux environment

1.1 After downloading the installation package of the Linux version, upload it to the specified folder of the Linux virtual machine and decompress it

cd mypackage #进入到自己的安装包存放位置,后把maven安装包上传到该位置
tar -zxvf apache-maven-3.8.6-bin.tar.gz  -C /usr/src #解压到指定目录
ln -s apache-maven-3.8.6/ /usr/src/maven3.86  #创建软链接,方便使用(它相当于一个快捷方式)

Note: The decompression to the specified location varies from person to person. Some people like to put it under /opt/local , whichever is fine. 

1.2 Enter /etc/profile to configure the environment variable and make it valid again, then use the mvn command to verify

1.2.1 Configure environment variables

vim /etc/profile  #进入后,下滑到底部,然后按键盘上的i,进入编辑

export MAVEN_HOME=/usr/src/apache-maven-3.8.6
export PATH=$PATH:$MAVEN_HOME/bin

As shown below:

If multiple environment variables have been configured before, just add MAVEN_HOME to the end of PATH. It should be noted that each environment variable is separated by a colon in English.

After the configuration is complete, press the ESC key and enter: wq to save and exit.

1.2.2 Use the source /etc/profile command to make the configuration file valid again, and use the mvn command to verify whether the configuration is successful

source /etc/profile #使资源配置文件重新生效
mvn -version #查看版本,正常打印说明配置成功

1.3 Modify the /conf/setting.xml file in the installation directory

cd /usr/src
ls
cd apache-maven-3.8.6 && ls
vim conf/settings.xml

1.3.1 Modify the storage location of the local warehouse

Ctrl+d or Ctrl+B, scroll up and down to find the location of the local warehouse configuration (at the top)

Uncomment and specify the local warehouse storage address as your favorite location, such as: /usr/local/repository

  

1.3.2 Modify the mirrors image

The default mirrors of the system are generally not what we want

Add your own mirror
Paste the following code inside the mirrors tag

<!--镜像仓库:默认使用阿里-->
<mirror>
	<!--指定镜像ID(自己可以改名)-->
	<id>alimaven</id>
	<!--指定镜像名称(自己可以改名)-->
	<name>aliyun maven</name>
	<!--匹配中央仓库(阿里云的仓库名称,必须这么写,不可以修改)-->
	<mirrorOf>central</mirrorOf>
	<!--指定镜像路径-->
	<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

As shown in the figure below, after the configuration is complete, save and exit. 

Two, Windows environment

Notice: The installation and configuration of this environment is exactly the same as the installation and configuration of the Linux environment, download --> unzip --> configure environment variables --> verify --> configure setting.xml

2.1 Download and unzip the installation package to your favorite location 

Unzip the downloaded maven-3.8.6-bin.zip installation package and put it in your favorite location, as shown in the figure below

2.2 Configure environment variables

Right-click "My Computer" on the desktop, and click "Properties", as shown in the following figure:

 Open the environment variable configuration interface, first configure MAVEN_HOME , and then configure Path

Click the OK button, find the Path below , click Edit, and add ;%MAVEN_HOME%\bin; to the end

Note: The front and back need to be separated by English semicolons

 

Reminder: Finally , you must click the OK button one by one to close multiple small windows ! ! !

2.3 Verify whether the configuration is successful

Win+R, enter cmd, open the command window, enter the mvn -v command, and check the maven version

 Note: If you have not installed and configured JDK in advance, an error may be reported here. For the installation and configuration of JDK , if you need help, click to enter .

2.4 Configure /conf/setting.xml file (local warehouse, mirror image)

Enter the conf folder of the Maven decompression directory, open it with Notepad or Notepad++, and edit

Find the following locations and configure the local warehouse storage location and mirroring respectively

<localRepository>D:\Program Files\services\repository</localRepository>

Configure mirroring

 <!--镜像仓库:默认使用阿里-->
		<mirror>
		    <!--指定镜像ID(自己可以改名)-->
			<id>alimaven</id>
			<!--指定镜像名称(自己可以改名)-->
			<name>aliyun maven</name>
			<!--匹配中央仓库(阿里云的仓库名称,必须这么写,不可以修改)-->
			<mirrorOf>central</mirrorOf>
			<!--指定镜像路径-->
			<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
		</mirror>

Note: When configuring, be careful not to add or miss angle brackets! ! !

Summarize

Whether it is a Linux environment or a Windows environment, the configuration steps are almost the same:

Download --> Unzip --> Configure environment variables --> Verify --> Configure setting.xml

Every step needs to be treated carefully. Don't write colons in English into Chinese, and don't add or miss angle brackets!

Epilogue

During the use of Maven , it has been configured many times. However, when building the RocketMQ environment today, I found that Maven needs to be installed in advance . I just take this opportunity to summarize and share it here, hoping to inspire and help you.

If you think it's not bad, welcome to like and collect!

notes

1. Maven Collection: Execute Maven commands with 5 different entries in IDEA

Guess you like

Origin blog.csdn.net/xp871038951/article/details/127530521