We will download and install maven on Mac. Replace commands below with more recent version numbers. During this operation we will also check the md5 hash to check if our download is the same as the file on the server. We will also learn how to untar a file unix style.
Download the software:
devbox$ cd ~/Development/software
devbox$ curl -O http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
Download the checksum from maven:
devbox$ curl -O https://www.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz.md5
Generate your own checksum against the downloaded file:
md5 -q apache-maven-3.5.0-bin.tar.gz > my-checksum.md5
Compare the two md5 hashes. If they are the same we know the downloaded file is not malformed during download. The -w option is to ignore any whitespaces (also newlines and tabs) during comparison. This is needed in this case because my md5 ends with a newline while maven’s md5 doesn’t and that would break the diff. No result running diff? That’s a good thing.
diff -w my-checksum.md5 apache-maven-3.5.0-bin.tar.gz.md5
Now let’s un-tar.
devbox$ tar xvzf apache-maven-3.5.0-bin.tar.gz
x -> Output to disk
v -> Verbose output (see output of what it is doing)
z -> Decompress
f -> Filename
The new un-tarred filename is apache-maven-3.5.0. This isn’t very easy to use. So let’s rename it and also clear the downloads.
devbox$ mv apache-maven-3.5.0 mvn
devbox$ rm apache-maven-3.5.0-bin.tar.gz
devbox$ rm apache-maven-3.5.0-bin.tar.gz.md5
devbox$ rm my-checksum.md5
Finally, mvn must be visible outside ~/Development/software/mvn. To do so we add this to the path variable. The fastest way is to redefine the PATH at the end of .bash_profile. The following command does that and will even create the file if it doesn’t exist. The source command is used to reload the file so we can use it right away.
devbox$ echo 'PATH=$PATH:~/Development/software/mvn/bin' >> ~/.bash_profile
devbox$ source ~/.bash_profile
Now let’s test. This should output the version we are using, but also the home directory where we’ve installed maven. Verify to see we are not being overruled by another installation.
devbox$ mvn -version