Ruby on Rails使用命令行“计算图像的md5

我正在试图在ruby脚本和ruby on rails服务器上生成图像的md5哈希。

在脚本(这是在Mac上本地运行)我正在做:

`md5 -q path-to-file` 

这工作得很好,生成一些像Added new md5: efe99a09e6e1b192314891b960018bd4当我在服务器上运行相同的命令(在Linux机器上生产运行),它成为一个空string

 def add_md5_if_empty(test_image) if md5.nil? self.md5 = `md5 -q #{test_image.image.path}` logger.info "Added new md5: #{self.md5} for image at path: #{test_image.image.path}" test_image.save end end I, [2016-02-24T03:48:36.879648 #42] INFO -- : Added new md5: for image at path: /app/public/system/test_images/images/000/209/309/original/filename.png 

我的猜测是,轨道服务器(Linux机器上)ruby没有md5命令。 另外我的项目是使用Docker,所以也许有一些依赖,我失踪了。 任何帮助将不胜感激。

纯ruby:

 require 'digest/md5' # ... self.md5 = Digest::MD5.hexdigest(File.binread(test_image.image.path)) 

编辑:更简单:

 self.md5 = Digest::MD5.file(test_image.image.path).hexdigest