Ruby: how to get the MD5 hash of a file

, posted

This post was last updated for Ruby 3.1.2.

To compute the MD5 hash of a file in Ruby, use Digest::MD5.file.

require "digest"

# => "272946d082eb5758a2bcbdaa2203bc8c"

This uses Digest::Class.file, the base class for Digest::MD5.

It took me awhile to find this, so hopefully I’ve saved you some time!