PostGIS通过PostgreSQL安装器安装时报错求助
Hey there! Let's tackle this installation headache step by step—you're not alone with these issues, especially when starting out with geocoding projects. Here's a structured approach to get you back on track:
1. Do a Full Cleanup of Residual Files
Manual deletion often misses hidden configs or data folders, which can cause repeat failures. Let's nuke every trace of PostgreSQL and PostGIS:
- First, stop any running PostgreSQL services:
sudo systemctl stop postgresql # For systemd-based systems (Ubuntu 16.04+, Debian) # Use this if systemctl doesn't work: # sudo service postgresql stop - Purge all related packages (Debian/Ubuntu example):
sudo apt purge postgresql* postgis* - Delete leftover system folders:
sudo rm -rf /var/lib/postgresql/ sudo rm -rf /etc/postgresql/ sudo rm -rf /usr/lib/postgresql/ - Clean up unused dependencies to free up space:
sudo apt autoremove && sudo apt autoclean
(For RHEL/CentOS users, replace apt with yum or dnf in the commands above.)
2. Fix Your Installation Sources & Update System
Outdated or mismatched package sources are a top cause of failed installs. Let's use official, reliable sources to avoid version conflicts:
- Update your system's package list first:
sudo apt update && sudo apt upgrade - Add the official PostgreSQL repository (this ensures you get PostGIS versions that perfectly match your PostgreSQL install):
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - Install a specific, compatible version (e.g., PostgreSQL 15 + PostGIS 3—replace
15with the version your tutorial recommends):sudo apt install postgresql-15 postgis postgresql-15-postgis-3
3. Fix the "sudo command not found" Error
This usually boils down to either a typo or a broken PATH environment variable:
- Double-check the command from the tutorial—did you misspell it? For example, mixing up
aptandapt-get, or missing a hyphen? - Verify your
PATHincludes system command directories:
Look forecho $PATH/usr/binand/usr/sbin—if they're missing, temporarily add them:export PATH=$PATH:/usr/bin:/usr/sbin - If all else fails, switch to the root user temporarily to run commands (not recommended for daily use, but useful for troubleshooting):
su - root # Run your installation commands here
4. Post-Install Verification
Once you get the installation to complete, confirm PostGIS is working properly before jumping back to your tutorial:
- Log into PostgreSQL as the default user:
sudo -u postgres psql - Create a test database and enable PostGIS:
CREATE DATABASE test_geocode; \c test_geocode; CREATE EXTENSION postgis; - Check the PostGIS version to confirm it's active:
SELECT PostGIS_Version();
If you see a version number returned, you're all set to continue with your geocoding project!
内容的提问来源于stack exchange,提问作者deadant88

