56

I tried to use sha256sum in High Sierra; I attempted to install it with MacPorts, as:

sudo port install sha256sum

It did not work.

What to do?

2

3 Answers 3

103

The CoreUtils package is also published as a Brew formulae. So if you have Brew installed you can also just run:

brew install coreutils

Then add PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" to ~/.bashrc, run source ~/.bashrc and you're done.

5
  • Congrats on your first answer in U&L. I prefer MacPorts to Brew, but yes, it is a viable alternative. Nov 27, 2018 at 11:48
  • 4
    This should be the accepted answer! May 22, 2019 at 11:46
  • 2
    @Milkncokiez If someone manages to convince me why a macports question ought to have as a correct answer a brew solution I am all ears. Aug 7, 2019 at 16:02
  • 1
    @RuiFRibeiro the OP didn't ask how to do get sha256sum using MacPorts specifically, they just said they attempted to get it using MacPorts. I found both answers very useful. Jul 1, 2020 at 16:39
  • @krookedking The question is tagged Macports, and I am the OP. ;-P Both answers are welcome and useful, it was just a tongue and cheek answer to a particular comment above. Jul 1, 2020 at 16:48
36

After investigating a little, I found a ticket in an unrelated software in GitHub sha256sum command is missing in MacOSX , with several solutions:

  • installing coreutils

    sudo port install coreutils
    

    It installs sha256sum at /opt/local/libexec/gnubin/sha256sum

  • As another possible solution, using openssl:

function sha256sum() { openssl sha256 "$@" | awk '{print $2}'; }
  • As yet another one, using the shasumcommand native to MacOS:
function sha256sum() { shasum -a 256 "$@" ; } && export -f sha256sum
1
  • 3
    +1 for openssl sha256 myfile which is available by default
    – NGI
    Oct 12, 2021 at 20:52
2

Supplemental Answer to Mig82's, whose answer handles the g-prefix for all executables in coreutils. I offer a tightly-scoped solution.

After coreutils installing with

brew install coreutils

Results in ls /usr/local/bin/gsha* will list the g-prefixed executables:

  • /usr/local/bin/gsha1sum
  • /usr/local/bin/gsha224sum
  • /usr/local/bin/gsha256sum
  • /usr/local/bin/gsha384sum
  • /usr/local/bin/gsha512sum

The solution is to create a symbolic link to the ones you want using a non-prefixed name (or take a risk in breaking some programs that rely on BSD executables and use the no g prefix Homebrew option)

Example

shaarray=(\
/usr/local/bin/gsha1sum
/usr/local/bin/gsha224sum
/usr/local/bin/gsha256sum
/usr/local/bin/gsha384sum
/usr/local/bin/gsha512sum
)
function installsha() {
  for i in "${shaarray[@]}"
  do
    printf "$i\n" | perl -pe 'printf $_; s/gsha/sha/' | xargs -n 2 ln -s
  done
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.