Raam Dev » thoughts essays journal notes contact about subscribe rss

HOWTO: Install md5sum & sha1sum on Mac OS X

I was a bit surprised to learn that my Mac didn’t have the md5sum and sha1sum tools installed by default. A quick search and I found a site that provides the source. The sources compiled successfully on my Mac (OS X 10.5.5, xCode tools installed).

The only quirk appears in the last step:

$ ./configure
$ make
$ sudo make install
cp md5sum sha1sum ripemd160sum /usr/local/bin
chown bin:bin /usr/local/bin/md5sum /usr/local/bin/sha1sum \
/usr/local/bin/ripemd160sum
chown: bin: Invalid argument
make: *** [install] Error 1

The make install command tries to change the ownership of the files to the bin user. Since that user doesn’t exist on my system, the command fails. This isn’t a problem though, as both binaries work perfectly. By default, they are installed to /usr/local/bin/.

Update
As a commenter pointed out, the /sbin/md5 utility provided by OS X contains a hidden -r switch that causes it to output in a format identical to that of md5sum, making it compatible with scripts that require md5sum’s format. If you want to use the md5 utility provided by OS X, you can add the following to your ~/.profile or ~/.bashrc:

alias md5='md5 -r'
alias md5sum='md5 -r'
  1. Thanks,
    Worked perfectly. Why would they take md5sum out of 10.5 from 10.4 ?

  2. Yeah, I have no idea why they would remove them from 10.5. Seems kinda silly since they are very basic and lightweight Unix tools.

  3. seems they only include md5, which may have a slightly different output to md5sum, but from what I gather, does the same thing..? still, they could have made md5sum symlink to md5

  4. Hey Nevyn,

    You’re absolutely correct! OS X includes /sbin/md5, however it’s output is different than the md5sum utility:


    $ md5 myfile.iso
    MD5 (myfile.iso) = 3d763a372e34681287712f661ecb598c

    $ md5sum myfile.iso
    3d763a372e34681287712f661ecb598c myfile.iso

    Many scripts that utilize the md5sum utility expect the output to be in a particular format. If the format is different (as it is with the md5 command), it will break the scripts that use it.

    • Arnost

      I had same problem, however, after a while of googling, I found that md5 has hidden switch -r

      $md5 myfile.txt
      MD5 (myfile.txt) = 2930560673edb5b823e0818265737914

      $md5 -r myfile.txt
      2930560673edb5b823e0818265737914 myfile.txt

  5. I haven't found an md5sum that wasn't exactly as calculated using md5 on the Mac. (OSX 10.4.11).
    For sha1sum you can do "openssl sha1 <path/filename.ext>".

  6. Hey Nuke,

    Were you able to compile the md5sum from scratch like I explained in the post?

  7. Eugene

    Won’t quite do the same since it won’t actually accept a source file to check sha1 sums against, but if you just need to generate compatible output, you could try defining the following function in your .bashrc:

    sha1sum ()
    {
    openssl sha1 $1 | sed ‘s/.*(\(.*\))= \(.*\)$/\2 \1/’
    }

    This will, on a “sha1sum foo.txt” generate the expected output…

  8. Travis

    Eugene’s trick works with md5 as well.

    md5sum ()
    {
    md5 -r $1
    }

  9. Wow why did they not include a compatible version? Anyway you hint worked a champ.
    Thanks!
    -roger-

  10. Richard Mitchell

    I would recommend installing homebrew and running ‘brew install coreutils’.

    http://mxcl.github.com/homebrew

  11. Antony

    $openssl md5 yourfile

Leave a Reply

Subscribe without commenting.


Readers who shared HOWTO: Install md5sum & sha1sum on Mac OS X

  1. md5sum recursive from ./ « kravca.mu shared this post on January 14, 2010 at 17:54
  2. Roberto Nogueira shared this post on May 7, 2010 at 15:17
  3. Lance Quejada shared this post on July 24, 2010 at 04:33
  4. Rffuste shared this post on July 2, 2011 at 07:56

Other posts you may enjoy:

Where in the world is Raam?

Join the Facebook Community

Raam Dev » thoughts essays journal notes contact about subscribe rss

Powered by WordPress and other Open Source Software
Uncopyright by Raam Dev