macOSでopensslコマンド打つとエラーになる


macで openssl コマンド使うとエラーになった。

% openssl x509 -in test.crt -text -noout
unable to load certificate
...

一応バージョンは
macOS Catalina 10.15.7

他のバージョンで発生するかは不明。

brewで入れてみる。

% brew install openssl
Updating Homebrew...

・
・
・

Error: Failed to link all completions, docs and manpages:
  Permission denied @ dir_s_mkdir - /usr/local/share/fish
Error: The following directories are not writable by your user:
/usr/local/lib/pkgconfig
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man1

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/lib/pkgconfig /usr/local/share /usr/local/share/man /usr/local/share/man/man1

And make sure that your user has write permission.
  chmod u+w /usr/local/lib/pkgconfig /usr/local/share /usr/local/share/man /usr/local/share/man/man1

なんかエラーが出たので言われたとおり実行。

% sudo chown -R $(whoami) /usr/local/lib/pkgconfig /usr/local/share /usr/local/share/man /usr/local/share/man/man1
Password:

% chmod u+w /usr/local/lib/pkgconfig /usr/local/share /usr/local/share/man /usr/local/share/man/man1

で、brew で openssl が入った。

が解消しない。

% which openssl
/usr/bin/openssl

これは brew で入ったものではない。

% brew link openssl
Warning: Refusing to link macOS provided/shadowed software: [email protected]
If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
  export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

言われた通り、

% echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

でターミナル新しく起動するとコマンドが通った。