首先确保你的mac上已经装有homebrew,可以通过命令行查询brew版本
brew info #查看homebrew的相关信息
brew help #查看homebrew相关命令
使用homebrew安装psql(postgresql,一下简称psql)
brew install postgresql
查看psql版本
pg_ctl -V
初始化psql数据库
initdb /usr/local/var/postgres
可能会出现错误
解决办法,如提示解决即可
#remove or empty the directory "/usr/local/var/postgres"
#run initdb with an argument other than "...."
cd /usr/local/var/postgres
rm -r * #清空当前文件夹下的所有文件
#再次运行就可
initdb /usr/local/var/postgres