99

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?

1

5 Answers 5

162

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.

2
  • Note that after brew install coreutils installation you will get a message like Caveats: Commands also provided by macOS and the commands dir, dircolors, vdir have been installed with the prefix "g". Commented Feb 19, 2023 at 21:11
  • Looks like it is now installed into /opt/homebrew/bin. Commented Jun 20, 2023 at 4:46
54

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
0
26

If you just need a CLI command, simply

shasum -a 256 <file>

solves the problem. It is not necessary to install coreutils.

This is mentioned, though not prominently visible, in the comment to this question and also in Rui F Ribeiro's answer.

1
  • Worked for me on 14.4.1 Commented May 16, 2024 at 13:09
7

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

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 symbolic links to the ones you want using non-prefixed names (handling all carries the risk of breaking some programs that rely on BSD executables)

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
}
0

Linux Command (sha256sums)

If you're looking for an alternative to this

sha256sum --check SHA256SUMS

MacOS Command (shasum)

Then use this instead on MacOS

shasum --algorithm 256 --check SHA256SUMS

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.