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/
.
Using the OS X md5 instead of md5sum
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'
Installing with HomeBrew
A commenter mentioned that you can install md5sum
using HomeBrew by running brew install coreutils
.
Update (2015-02-25): The current method for installing via HomeBrew is as follows:
brew install md5sha1sum
Installing with MacPorts
A commenter mentioned if you have MacPorts installed, you can run port install coreutils
but "you’ll need to add /opt/local/libexec/gnubin/
to your PATH
.
Update (2014-08-25): It appears that you should use sudo port install md5sha1sum
.
Thanks,
Worked perfectly. Why would they take md5sum out of 10.5 from 10.4 ?
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.
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
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.
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
Wow, that’s awesome! Thanks Arnost!
Hidden? It’s in the man page…
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>".
Hey Nuke,
Were you able to compile the md5sum from scratch like I explained in the post?
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…
Thanks for the tip, Eugene!
Eugene’s trick works with md5 as well.
md5sum ()
{
md5 -r $1
}
Thanks for the tip, Travis! I actually rewrote about this problem on my tech blog and used a similar solution:
http://solidstateraam.com/mac-os-x-replicating-md5sum-output-format/
Wow why did they not include a compatible version? Anyway you hint worked a champ.
Thanks!
-roger-
I would recommend installing homebrew and running ‘brew install coreutils’.
http://mxcl.github.com/homebrew
Thanks for the tip, Richard! 🙂
Thank you Richard!
port install coreutils also works for macports.
you’ll need to add /opt/local/libexec/gnubin/ to your PATH.
Thanks for the tip, Ray! I’ve updated the post to include your note when using MacPorts.
(Sorry for the delayed reply; I’m just catching up to comments now!)
$openssl md5 yourfile
Thank you for the tip, Antony! 🙂
for those of you using brew: ‘brew install md5sha1sum’
Thanks for the tip, Kris! 🙂
Thank you for the comment about -r option, was really usefull for me as I’m moving my video files from my iMac to a file server running Debian GNU/Linux and using md5sum to verify data integrity after copy.
Actually I’ve got an addon:
the -r hidden option does not really respect the format, indeed if you do something like:
ssh user@imac “cd /Volumes/To/Copy; find . -type f -print0 | xargs -0 md5 -r” | md5sum -c
using the check option (-c) on linux side, then it will complain that the md5 output format is not valid. Indeed. MacOSX md5 -r generates lines with “” separated with *one* space with the “”. However, the Linux version of md5sum requires 2.
So you can add “| sed s’/ / /’ |” and it will work like a charm 🙂
Thank you again for this information.
Thanks so much for the added tips, Alexis! 🙂
Does not appear to work at all in Maverick.
—–Using your method just bombs:
$ ./configure
setting prefix… /usr/local
checking system type… Interestink. OS X
checking for a C compiler… /usr/bin/gcc
checking to see if /usr/local/bin/md5sum is Microbrew… does not exist
checking to see if /usr/local/bin/sha1sum is Microbrew… does not exist
checking to see if /usr/local/bin/ripemd160sum is Microbrew… does not exist
looking for OpenSSL headers ‘openssl/md5.h’… Cannot find it.
Please run this script as such: SSLINCPATH= ./configure
$ make
Makefile:27: sys-setup.mk: No such file or directory
Please run ‘configure’ first.
make: /bin/false: No such file or directory
make: *** [sys-setup.mk] Error 1
——Using mac ports returns nothing:
$ sudo port install md5sum
Warning: port definitions are more than two weeks old, consider using selfupdate
Error: Port md5sum not found
To report a bug, see
$ sudo port install sha1sum
Warning: port definitions are more than two weeks old, consider using selfupdate
Error: Port sha1sum not found
To report a bug, see
$ which md5sum
$ which sha1sum
Try `sudo port install md5sha1sum`.
On my Mac with Mavericks I discovered there’s a program called shasum which seems to be the same thing as sha1sum. I can use shasum on my Mac from a Terminal window and get the same checksum as using sha1sum on Linux.
Sorry I said Mavericks above. I am actually running Yosemite OS X 10.10.
Thanks for this 🙂
You’re most welcome, Colby! 🙂
The current way to do this is:
brew install md5sha1sum
Thank you for pointing that out! 🙂 I’ve updated the post.
Thanks bro!
Glad I could help! 🙂
Does this support SHA-256?
You saved my day 🙂
I’m glad that I could help, Bart! 🙂
Saved my day. Thank you.
You’re welcome, Raja! I’m happy I could help.
Hello,
I am trying to download this software for my Mac to analyze miRNA sequencing data. Can you please instruct me how to download Md5sum?
Thank you
Pooja
Hello Pooja,
The post that you commented on explains how to download
md5sum
on the Mac. You’ll need to install Homebrew, and then you can runbrew install md5sha1sum
, or alternatelybrew install coreutils
, which includes bothmd5sum
andsha1sum
.