<\/span><\/h2>\r\n\r\n\r\n\r\nFirst, log in to your Ubuntu 20.04 server via SSH as the root user:<\/p>\r\n\r\n\r\n\r\n
ssh root@IP_Address -p Port_number<\/pre>\r\n\r\n\r\n\r\nYou will need to replace ‘IP_Address’ and ‘Port_number’ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the admin account if necessary.<\/p>\r\n\r\n\r\n\r\n
Before starting, you have to make sure that all Ubuntu OS packages installed on the server are up to date. You can do this by running the following commands:<\/p>\r\n\r\n\r\n\r\n
apt-get update -y\r\napt-get upgrade -y<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 2: Install Java<\/span><\/h2>\r\n\r\n\r\n\r\nApache Maven is based on Java. So you will need to install Java in your system. You can install it with the following command:<\/p>\r\n\r\n\r\n\r\n
apt-get install default-jdk -y<\/pre>\r\n\r\n\r\n\r\nOnce installed, verify the Java version with the following command:<\/p>\r\n\r\n\r\n\r\n
java -version<\/pre>\r\n\r\n\r\n\r\nYou should get the Java version in the following output:<\/p>\r\n\r\n\r\n\r\n
openjdk version \"11.0.9.1\" 2020-11-04\r\nOpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)\r\nOpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)\r\n<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 3: Install Apache Maven from Source<\/span><\/h2>\r\n\r\n\r\n\r\nIn this section, we will show you how to install Apache Maven from the source. This way you can install the latest version of Apache Maven in your system.<\/p>\r\n\r\n\r\n\r\n
Download Apache Maven<\/h3>\r\n\r\n\r\n\r\n
First, download the latest version of Apache Maven to the \/opt directory with the following command:<\/p>\r\n\r\n\r\n\r\n
cd \/opt\r\nwget https:\/\/downloads.apache.org\/maven\/maven-3\/3.6.3\/binaries\/apache-maven-3.6.3-bin.tar.gz<\/pre>\r\n\r\n\r\n\r\nOnce the download is completed, extract the downloaded file with the following command:<\/p>\r\n\r\n\r\n\r\n
tar xzf apache-maven-3.6.3-bin.tar.gz<\/pre>\r\n\r\n\r\n\r\nNext, rename the extracted directory with the following command:<\/p>\r\n\r\n\r\n\r\n
mv apache-maven-3.6.3 apachemaven<\/pre>\r\n\r\n\r\n\r\nSetup Environment Variable<\/h3>\r\n\r\n\r\n\r\n
Next, you will need to setup environment variable to define the Java and Apache Maven path. To do so, create a new file named apachemaven.sh inside \/etc\/profile.d\/ directory:<\/p>\r\n\r\n\r\n\r\n
nano \/etc\/profile.d\/apachemaven.sh<\/pre>\r\n\r\n\r\n\r\nAdd the following lines:<\/p>\r\n\r\n\r\n\r\n
export JAVA_HOME=\/usr\/lib\/jvm\/default-java\r\nexport M2_HOME=\/opt\/apachemaven\r\nexport MAVEN_HOME=\/opt\/apachemaven\r\nexport PATH=${M2_HOME}\/bin:${PATH}\r\n<\/pre>\r\n\r\n\r\n\r\nSave and close the file then give the execution permission:<\/p>\r\n\r\n\r\n\r\n
chmod +x \/etc\/profile.d\/apachemaven.sh<\/pre>\r\n\r\n\r\n\r\nNext, activate the environment variable with the following command:<\/p>\r\n\r\n\r\n\r\n
source \/etc\/profile.d\/apachemaven.sh<\/pre>\r\n\r\n\r\n\r\nVerify the Apache Maven<\/h3>\r\n\r\n\r\n\r\n
Now, you can verify the Apache Maven installation using the following command:<\/p>\r\n\r\n\r\n\r\n
mvn -version<\/pre>\r\n\r\n\r\n\r\nIf everything is fine, you should get the following output:<\/p>\r\n\r\n\r\n\r\n
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)\r\nMaven home: \/opt\/apachemaven\r\nJava version: 11.0.9.1, vendor: Ubuntu, runtime: \/usr\/lib\/jvm\/java-11-openjdk-amd64\r\nDefault locale: en_US, platform encoding: UTF-8\r\nOS name: \"linux\", version: \"5.4.0-29-generic\", arch: \"amd64\", family: \"unix\"\r\n<\/pre>\r\n\r\n\r\n\r\n