在Linux下安装PostgreSQL,可以按照以下步骤进行:
sudo apt update
对于基于Debian的系统(如Ubuntu):
sudo apt install postgresql postgresql-contrib
对于基于Red Hat的系统(如CentOS、Fedora):
sudo yum install postgresql-server postgresql-contrib
或者使用dnf(Fedora 22+):
sudo dnf install postgresql-server postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresql
检查PostgreSQL服务状态:
sudo systemctl status postgresql
sudo apt-get update
sudo apt-get install build-essential libpq-dev
访问PostgreSQL官方网站,下载最新版本的源码包,例如:
wget https://ftp.postgresql.org/pub/source/v14.3/postgresql-14.3.tar.gz
tar -zxvf postgresql-14.3.tar.gz
cd postgresql-14.3
./configure --prefix=/usr/local/pgsql --with-libpq=/usr/lib/x86_64-linux-gnu --with-openssl=/usr/bin/openssl
make
sudo make install
sudo mkdir /usr/local/pgsql/data
sudo chown $USER /usr/local/pgsql/data
cd /usr/local/pgsql/bin
./initdb -D /usr/local/pgsql/data
./pg_ctl -D /usr/local/pgsql/data start
将PostgreSQL的bin目录添加到PATH中:
echo 'export PATH=$PATH:/usr/local/pgsql/bin' >> ~/.bashrc
source ~/.bashrc
检查PostgreSQL服务状态:
pg_ctl -D /usr/local/pgsql/data status
sudo进行操作。通过以上步骤,你应该能够在Linux系统上成功安装PostgreSQL。