如何在Linux(Ubuntu)上安装Maven

We can install Maven on Linux in a few simple steps. The first step is to install JDK because Maven needs it to execute.

我们可以通过几个简单的步骤在Linux上安装Maven。 第一步是安装JDK,因为Maven需要它才能执行。

In this tutorial, we will learn how to install Maven in Ubuntu. The steps are generic and it will work fine on any other Linux system too.

在本教程中,我们将学习如何在Ubuntu中安装Maven。 这些步骤是通用的,它也可以在其他Linux系统上正常工作。

在Linux / Ubuntu上安装JDK (Installing JDK on Linux/Ubuntu)

Generally, we use apt package manager to install anything in Ubuntu. But, it doesn’t have the latest JDK packages. The current version is Java 13 but the command apt list -a | grep openjdk shows only available OpenJDK versions are 8 and 11.

通常,我们使用apt软件包管理器在Ubuntu中安装任何东西。 但是,它没有最新的JDK软件包。 当前版本是Java 13,但是命令apt list -a | grep openjdk apt list -a | grep openjdk显示只有可用的OpenJDK版本是8和11。

So, we will install JDK using binaries and setting some required environment variables.

因此,我们将使用二进制文件安装JDK并设置一些必需的环境变量

步骤1:下载JDK Binaries (Step 1: Download the JDK Binaries)

Go to the URL: https://jdk.java.net/13/

转到URL: https : //jdk.java.net/13/

Copy the download link for Linux/x64 build. Then use the below command to download and extract it.

复制Linux / x64构建的下载链接。 然后使用以下命令下载并解压缩它。

$ wget https://download.java.net/java/GA/jdk13.0.1/cec27d702aa74d5a8630c65ae61e4305/9/GPL/openjdk-13.0.1_linux-x64_bin.tar.gz
$ tar -xvf openjdk-13.0.1_linux-x64_bin.tar.gz
$ mv jdk-13.0.1 /opt/

I have moved JDK to /opt, you can keep it anywhere in the file system.

我已将JDK移至/ opt,您可以将其保留在文件系统中的任何位置。

步骤2:设置JAVA_HOME和路径环境变量 (Step 2: Setting JAVA_HOME and Path Environment Variables)

Open .profile file from the home directory and add the following lines to it.

从主目录打开.profile文件,并在其中添加以下几行。

JAVA_HOME='/opt/jdk-13.0.1'
PATH="$JAVA_HOME/bin:$PATH"
export PATH

You can relaunch the terminal or execute source .profile command to apply the configuration changes.

您可以重新启动终端或执行source .profile命令以应用配置更改。

步骤3:验证Java安装 (Step 3: Verify the Java Installation)

You can run java -version command to verify the JDK installation.

您可以运行java -version命令来验证JDK的安装。

$ java -version
openjdk version "13.0.1" 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
$

在Linux / Ubuntu上安装Maven (Installing Maven on Linux/Ubuntu)

We will install Maven in a similar way that we have installed JDK in the Linux system.

我们将以与在Linux系统中安装JDK相似的方式安装Maven。

步骤1:下载Maven二进制文件 (Step 1: Download the Maven Binaries)

Go to the URL: https://maven.apache.org/download.cgi

转到URL: https : //maven.apache.org/download.cgi

Copy the link for the “Binary tar.gz archive” file. Then run the following commands to download and untar it.

复制“二进制tar.gz存档”文件的链接。 然后运行以下命令下载并解压缩。

$ wget https://mirrors.estointernet.in/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
$ tar -xvf apache-maven-3.6.3-bin.tar.gz
$ mv apache-maven-3.6.3 /opt/

步骤2:设置M2_HOME和路径变量 (Step 2: Setting M2_HOME and Path Variables)

Add the following lines to the user profile file (.profile).

将以下行添加到用户配置文件(.profile)。

M2_HOME='/opt/apache-maven-3.6.3'
PATH="$M2_HOME/bin:$PATH"
export PATH

Relaunch the terminal or execute source .profile to apply the changes.

重新启动终端或执行source .profile以应用更改。

步骤3:验证Maven安装 (Step 3: Verify the Maven installation)

Execute mvn -version command and it should produce the following output.

执行mvn -version命令,它将产生以下输出。

$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 13.0.1, vendor: Oracle Corporation, runtime: /opt/jdk-13.0.1
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"
$

That’s all. Maven is successfully installed in your Linux system.

就这样。 Maven已成功安装在您的Linux系统中。

翻译自: https://www.journaldev.com/33588/install-maven-linux-ubuntu

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值