Ubuntu按官方步骤安装pgadmin4失败,提示无安装候选包如何解决
报错信息:Package pgadmin4 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source. E: Package 'pgadmin4' has no installation candidate.
你遇到的源配置写入失败问题可通过手动配置源的方式解决,步骤如下:
第一步:确认当前Ubuntu版本代号
执行命令查看版本代号:lsb_release -cs
命令会输出对应版本的代号,例如22.04对应jammy、20.04对应focal、24.04对应noble,记录该值备用。第二步:手动写入源配置文件
执行命令创建并打开源配置文件:sudo nano /etc/apt/sources.list.d/pgadmin4.list
在打开的编辑器中输入以下内容,将<版本代号>替换为上一步查询到的实际值:deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/<版本代号> pgadmin4 main
按下Ctrl+O保存,回车确认文件名,再按下Ctrl+X退出编辑器。
可执行cat /etc/apt/sources.list.d/pgadmin4.list确认内容是否正确写入。第三步:导入pgadmin官方公钥
未导入公钥会导致源校验失败,执行命令导入:curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/packages_pgadmin_org.gpg
若系统未安装curl,先执行sudo apt install -y curl安装即可。第四步:更新apt缓存并安装
执行缓存更新命令:sudo apt update
缓存更新完成后即可正常安装pgadmin4:- 仅安装桌面端:
sudo apt install pgadmin4-desktop - 仅安装web端:
sudo apt install pgadmin4-web - 安装完整版本:
sudo apt install pgadmin4
- 仅安装桌面端:
如果官方源访问速度较慢,可将源配置中的地址替换为国内镜像站地址,例如清华源对应地址为https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/pgadmin/pgadmin4/apt/<版本代号>,其余操作步骤不变。
此前官方命令执行失败的常见原因是精简版Ubuntu系统未预装lsb-release包,导致命令中的变量替换失效,写入的源内容不符合要求,手动填写版本代号即可规避该问题。
内容的提问来源于stack exchange,提问作者Dylanthemachine

