Press "Enter" to skip to content

如果在centos7环境安装maven

Step 1: Update the System

To begin, let’s update the system’s package repositories and installed packages. Open the terminal and run the following command:

sudo yum update

Step 2: Install Java Development Kit (JDK)

Apache Maven on CentOS requires Java to be installed on your system. We will install the OpenJDK package, which is a free and open-source implementation of the Java Development Kit. Enter the following command in the terminal:

 yum install java-1.8.0-openjdk-devel

Step 3: Downloading Apache Maven

Next, we need to download the latest stable version of Apache Maven on CentOS. Visit the official Apache Maven website (https://maven.apache.org/download.cgi) and locate the link to the Binary tar.gz archive. Copy the link address for the most recent release.

Back in the terminal, navigate to the directory where you want to store the Apache Maven on CentOS installation package and use the wget command to download it. Replace the link below with the copied URL:

# cd /opt
# wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz
# tar zxvf apache-maven-3.9.6-bin.tar.gz

Step 4: Configuring Environment Variables

To configure the environment variables for Apache Maven, we will create a new file called maven.sh in the /etc/profile.d/ directory. Run the following command:

sudo nano /etc/profile.d/maven.sh

Add the following lines to the file:

cat /etc/profile.d/maven.sh
export JAVA_HOME=/usr/lib/jvm/jdk-1.8.0-openjdk
export M2_HOME=/opt/apache-maven-3.9.6
export MAVEN_HOME=/opt/apache-maven-3.9.6
export PATH=${M2_HOME}/bin:${PATH}

We need to make the maven.sh script executable. Execute the following command:

sudo chmod +x /etc/profile.d/maven.sh

Step 5: Apply Environment Variables

To apply the newly added environment variables, either restart your system or run the following command in the terminal:

source /etc/profile.d/maven.sh

To verify that Maven is correctly installed, enter the following command:

mvn -version

You should see the Maven version and other details printed on the console if the installation was successful.

参考资料:

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注