Une erreur s'est produite.

L'erreur a été envoyée par e-mail à l'administrateur pour analyse.

How do I install the latest version of maven.

Install maven from the source code.

Hello, my name is Christopher Tate. I am a Red Hat consultant and I love open source software. Most enterprises use Java today to build their applications and microservices, including governments, banks, accounting and businesses. Building java applications begins with installing Maven. The default version of Maven on your Linux distribution may be out of date to install certain open source software. I will help you install the most recent version of Maven to develop your website the open source way.

How do I install the dependencies for Maven?

Build the dependencies with yum.

sudo yum-builddep -y maven
  1. sudo: The command to install yum repositories begins with the command sudo. The "sudo" command allows your current user to have root privileges for a few minutes after entering your password.
  2. yum Stands for "Yellowdog Updater Modified", but nobody knows it as yellowdog, just yum. yum-builddep installs missing dependencies for building an RPM package.
  3. -y: Suppress messages asking to confirm if you want to install the software.
  4. maven: The package name you wish to install the dependencies for.
sudo yum install -y git
  1. sudo
  2. yum
  3. install: For installing new yum packages.
  4. -y
  5. git: The distributed revision control system for most open source software.

Where do I put the Maven source code?

Create a maven directory in /usr/local/src.

sudo install -d -o $USER -g $USER /usr/local/src/maven
  1. sudo
  2. install: Creates directories and sets attributes on the new directory.
  3. -d: Create directories.
  4. -o: Set ownership on the directory (super-user only).
  5. $USER: The current user to make the owner of the directory.
  6. -g: Set group ownership on the directory (super-user only).
  7. $USER: The current user to make the group owner of the directory.
  8. /usr/local is a place for extra software that you install without the package manager. /usr/local/src is a good place to clone your open source software repositories.

Where do I install Maven?

Create a maven directory in /opt.

sudo install -d -o $USER -g $USER /opt/maven
  1. sudo
  2. install
  3. -d
  4. -o
  5. $USER
  6. -g
  7. $USER
  8. /opt is a good place to install open source software applications like maven.

How do I download the maven source code?

Clone the source code with the git command.

git clone https://git-wip-us.apache.org/repos/asf/maven.git /usr/local/src/maven
  1. git: The distributed revision control system for most open source software.
  2. clone: Clone a repository into a directory.
  3. https://git-wip-us.apache.org/repos/asf/maven.git: The git URL to the maven source code repository.
  4. /usr/local/src/maven: The directory where the maven source code will be cloned.

How do I pick a recent version of Maven?

List all the tags in the git repository.

(cd /usr/local/src/maven && git tag)
  1. (cd: Change directory temporarily, because of the open parenthesis.
  2. /usr/local/src/maven: The directory where the maven source code was cloned.
  3. &&: Run the cd and git command together.
  4. git
  5. tag): Lists the current tags or assigned versions of the code and close the parenthesis.

How do I switch versions of the maven source code?

Checkout the git tag.

(cd /usr/local/src/maven && git checkout maven-3.6.1)
  1. (cd
  2. /usr/local/src/maven
  3. &&
  4. git
  5. checkout: Checkout a branch to the working tree.
  6. maven-3.6.1): The latest tag to base the branch from.

How do I build the maven source code?

Build Maven with the mvn command.

(cd /usr/local/src/maven && mvn -DdistributionTargetDir="/tmp/maven" clean package)
  1. (cd
  2. /usr/local/src/maven
  3. &&
  4. mvn: The java software project management tool.
  5. -DdistributionTargetDir="/tmp/maven": Point the distributionTargetDir to a temporary directory in /tmp.
  6. clean: Clean up any previous builds.
  7. package): Build the complete maven application and close the parenthesis.
rsync -r /tmp/maven/ /opt/maven/
  1. rsync: a fast, versatile, remote (and local) file-copying tool.
  2. -r: Recurse into directories.
  3. /tmp/maven/: The directory where the maven application was built. /tmp/maven/: Don't forget the ending slash or rsync assumes it's a file inside the destination.
  4. /opt/maven/: The directory where the maven will be installed. /opt/maven/: It's best to always write directories with a trailing slash in rsync for fewer surprises.

But why are we installing Maven to install the latest Maven?

A program that requires itself to build itself.

I couldn't believe it myself at first, a program that requires itself to build itself? The best I can do to explain this phenomenon is to quote the maven documentation: "Until Maven 3.3, Maven core build could be boostrapped with an Ant build. This bootstrap has been removed in Maven 3.5: you need a pre-built Maven to build Maven from source."

How do I change the default mvn command on the system?

Backup the original and make a symbolic link.

which mvn
  1. which: Shows the full path of commands in the $PATH.
  2. mvn: The command we want to backup and upgrade.
mvn -v
  1. mvn
  2. -v: View the version of maven on the system.
sudo mv /usr/bin/mvn /usr/bin/mvn3.0.5
  1. sudo
  2. mv: Move or rename files.
  3. /usr/bin/mvn: The old mvn command to backup.
  4. /usr/bin/mvn3.0.5: The path to the backup file.
sudo ln -s /opt/maven/bin/mvn /usr/local/bin/mvn
  1. sudo
  2. ln: Makes links between files.
  3. -s: Make symbolic links instead of hard links.
  4. /opt/maven/bin/mvn: The path to the new mvn file.
  5. /usr/local/bin/mvn: The path to the symbolic link in the $PATH.

Now try out the new binary and see that it's properly upgraded!

which mvn
mvn -v

To review:

Wednesday
May 8 2019 How do I install the latest version of maven. Install maven from the source code. By Christopher Tate
Questions Answers
How do I install the dependencies for Maven? Build the dependencies with yum.
Where do I put the Maven source code? Create a maven directory in /usr/local/src.
Where do I install Maven? Create a maven directory in /opt.
How do I download the maven source code? Clone the source code with the git command.
How do I pick a recent version of Maven? List all the tags in the git repository.
How do I switch versions of the maven source code? Checkout the git tag.
How do I build the maven source code? Build Maven with the mvn command.
But why are we installing Maven to install the latest Maven? A program that requires itself to build itself.
How do I change the default mvn command on the system? Backup the original and make a symbolic link.

Previous and next articles.

Don't give up on your dreams. You can do hard things!

Share this story.

Let's get connected.
Up to the top.