For Mac user find the version of the libgs.x.xx.dylib in your /usr/local/lib/ or /opt/homebrew/Cellar/ghostscript/x.xx.x/lib directory.
Then run this command,
ln -s /usr/local/lib/libgs.x.xx.dylib /usr/local/lib/libgs.so
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/' >> ~/.zshrc
Replace .zshrc with your shell script type.
[replace x.xx with the version in your directory]