MacOS无sha256sum工具:High Sierra下MacPorts安装失败求助
Hey there! Let's tackle this sha256sum issue on macOS High Sierra step by step.
shasum You don't even need to install anything first—macOS comes with a built-in tool called shasum that can do exactly what sha256sum does. Just run:
shasum -a 256 [your-file-path]
If you want output that matches sha256sum's exact format (like removing the asterisk before filenames), add the --binary flag:
shasum -a 256 --binary [your-file-path]
For even more convenience, set up an alias so you can type sha256sum directly from now on:
echo 'alias sha256sum="shasum -a 256"' >> ~/.bash_profile source ~/.bash_profile
If you really want the native GNU sha256sum tool, it's part of the coreutils package (not a standalone port). Let's troubleshoot the MacPorts issue:
- Update MacPorts first
Outdated package indexes are a common culprit. Refresh MacPorts and its repo:
sudo port selfupdate
Then try installing coreutils again:
sudo port install coreutils
After installation, the GNU tools will have a g prefix (e.g., gsha256sum). To use sha256sum directly, add MacPorts' GNU bin directory to your PATH:
echo 'export PATH="/opt/local/libexec/gnubin:$PATH"' >> ~/.bash_profile source ~/.bash_profile
- Install a compatible version for High Sierra
High Sierra is an older macOS release, so some newercoreutilsversions might not support it. Try installing a known-compatible version:
sudo port install coreutils @8.32_0
- Verify system permissions
Make sure your/opt/localdirectory has the correct permissions (MacPorts needs this to install packages):
sudo chown -R root:wheel /opt/local sudo chmod -R 755 /opt/local
If MacPorts keeps giving you trouble, Homebrew tends to have better compatibility with older macOS versions. First install Homebrew (if you haven't already):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then install coreutils:
brew install coreutils
Like with MacPorts, you'll get gsha256sum by default. To use sha256sum directly, add this to your profile:
echo 'export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"' >> ~/.bash_profile source ~/.bash_profile
内容的提问来源于stack exchange,提问作者Rui F Ribeiro

