Under Linux maven download, upload and install

To run maven, must have JDK, maven is written in the Java language

A, JDK installation

ORACLE official website to download JDK jdk-8u231-linux-x64.tar.gz

Upload to JDK linux server

Create a folder

[root@VM_0_17_centos /]# cd /opt
[root@VM_0_17_centos opt]# mkdir jdk

Use xftp tool to upload the compressed file

  • Connected Linux servers

UTOOLS1573054063264.png

UTOOLS1573054139114.png

  • If the folder permissions is not enough, may cause the file upload fails, you need to modify folder permissions
# 修改 opt 文件夹权限
chmod 777 /opt  
# 修改 opt 文件夹及其子目录的权限
chmod -R 777 /opt  

Install the JDK

After you upload the files unzipped successfully

[root@VM_0_17_centos jdk]# tar -zxvf jdk-8u231-linux-x64.tar.gz 
[root@VM_0_17_centos jdk]# ll
total 189608
drwxr-xr-x 7   10  143      4096 Oct  5 18:13 jdk1.8.0_231
-rw-r--r-- 1 root root 194151339 Nov  6 20:07 jdk-8u231-linux-x64.tar.gz

Configuring JDK environment variables

In the / etc / profile file append the following lines

 [root@VM_0_17_centos jdk]# vi /etc/profile
# 进入 vi 模式后 输入两个大 G ,定位到 文件末行
  • Additional variables

I input into edit mode

export JAVA_HOME=/opt/jdk/jdk1.8.0_231
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

UTOOLS1573054318178.png

Press the Esc key, enter : wq save and exit vi

  • The environment variables to take effect
[root@VM_0_17_centos jdk]# source /etc/profile
  • Check the JDK is in effect
[root@VM_0_17_centos jdk]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

Two, maven installation

Download Maven the Apache Maven 3.6.2

Download maven

  • linux using wget command to download maven
[root@VM_0_17_centos opt]# mkdir maven
[root@VM_0_17_centos opt]# cd maven
[root@VM_0_17_centos maven]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz

Create a folder and change to the directory, wget will address corresponding to the file download directory

Installation maven

  • Extract the installation files
[root@VM_0_17_centos maven]# ls
apache-maven-3.6.2-bin.tar.gz
[root@VM_0_17_centos maven]# tar -zxvf apache-maven-3.6.2-bin.tar.gz 
  • Create a soft link pointing to apache-maven-3.6.2 directory
[root@VM_0_17_centos maven]# ln -s apache-maven-3.6.2 maven
[root@VM_0_17_centos maven]# ll
total 8936
drwxr-xr-x 6 root root    4096 Nov  6 21:40 apache-maven-3.6.2
-rw-r--r-- 1 root root 9142315 Sep  3 05:43 apache-maven-3.6.2-bin.tar.gz
lrwxrwxrwx 1 root root      18 Nov  6 21:43 maven -> apache-maven-3.6.2

ln -s source file destination is a command in linux, windows in shortcuts all know it, this is equivalent to the source file to create a shortcut, called the name of the shortcut target file.
ln -s apache-maven-3.6.2 maven refers to apache-maven-3.6.2 Creating a shortcut maven, maven access equivalent access apache-maven-3.6.2.
Why here you need a shortcut?
After the upgrade is more convenient maven, maven later if we need to upgrade to the latest version, such as 3.7, then simply download the 3.7 to the current directory, then run the ln -s apache-maven-3.7 maven command to modify the shortcut to point on the line, very convenient.

Configuring maven environment

In the / etc / profile file append the following lines

export M2_HOME=/opt/maven/maven
export PATH=$M2_HOME/bin:$PATH
  • The environment variables to take effect
[root@VM_0_17_centos maven]# source /etc/profile
  • Check whether the entry into force maven
[root@VM_0_17_centos maven]# mvn -v
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T23:06:16+08:00)
Maven home: /opt/maven/maven
Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: /opt/jdk/jdk1.8.0_231/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.21.3.el7.x86_64", arch: "amd64", family: "unix"

Configuration setting.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">


  <localRepository>/opt/maven/repository</localRepository>

  <pluginGroups>


  </pluginGroups>

  <proxies>

  </proxies>

  <servers>

  </servers>


  <mirrors>
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
    <mirror>
        <id>ui</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://uk.maven.org/maven2/</url>
    </mirror>
    <mirror>
        <id>jboss-public-repository-group</id>
        <mirrorOf>central</mirrorOf>
        <name>JBoss Public Repository Group</name>
        <url>http://repository.jboss.org/nexus/content/groups/public</url>
    </mirror>
    <mirror>
        <id>repo2</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://repo2.maven.org/maven2/</url>
    </mirror>
    <mirror>
        <id>OSChina</id>
        <name>OSChina Central</name>
        <url>http://maven.oschina.net/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
    <mirror>
        <id>nexus-osc-thirdparty</id>
        <mirrorOf>thirdparty</mirrorOf>
        <name>Nexus osc thirdparty</name>
        <url>http://maven.oschina.net/content/repositories/thirdparty/</url>
    </mirror>
  </mirrors>


  <profiles>
    <profile>    
        <id>jdk-1.8</id>    
        <activation>    
            <activeByDefault>true</activeByDefault>    
            <jdk>1.8</jdk>    
        </activation>    
        <properties>    
            <maven.compiler.source>1.8</maven.compiler.source>    
            <maven.compiler.target>1.8</maven.compiler.target>    
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
        </properties>    
    </profile> 
  </profiles>


</settings>

Reference link: https: //mp.weixin.qq.com/s/7LGakBJvQUjiVEUgdSe_Aw

Guess you like

Origin www.cnblogs.com/mytripod/p/11809508.html