others-How to solve 'Unable to locate package postgresql-13' error on ubuntu system?

1. Purpose

In this post, I would demonstrate how to solve the following error when trying to install postgresql 13 on ubuntu 20.

E: Unable to locate package postgresql-13


Environment:

ubuntun system 20
postgresql 13



2. The solution

2.1 The solution to above error

Add postgresql apt repo and download the asc certification file:

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 -


Update your apt local packages:

sudo apt-get update


Start install pg 13:

sudo apt-get -y install postgresql-13


Then I got this:

 ⚡ root@launch-advisor-20191120  ~  sudo apt-get -y install postgresql-13
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm9 libpq5 libtypes-serialiser-perl pgdg-keyring postgresql-client-13 postgresql-client-common postgresql-common ssl-cert
Suggested packages:
  postgresql-doc-13 openssl-blacklist
The following NEW packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm9 libpq5 libtypes-serialiser-perl pgdg-keyring postgresql-13 postgresql-client-13 postgresql-client-common postgresql-common ssl-cert
0 upgraded, 12 newly installed, 0 to remove and 33 not upgraded.
Need to get 32.1 MB of archives.
After this operation, 127 MB of additional disk space will be used.
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 libcommon-sense-perl amd64 3.74-2build6 [20.1 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 libjson-perl all 4.02000-2 [80.9 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 libtypes-serialiser-perl all 1.0-1 [12.1 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 libjson-xs-perl amd64 4.020-1build1 [83.7 kB]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 libllvm9 amd64 1:9.0.1-12 [14.8 MB]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu focal/main amd64 ssl-cert all 1.0.39 [17.0 kB]
Get:7 http://apt.postgresql.org/pub/repos/apt focal-pgdg/main amd64 libpq5 amd64 14.2-1.pgdg20.04+1 [170 kB]
Get:8 http://apt.postgresql.org/pub/repos/apt focal-pgdg/main amd64 pgdg-keyring all 2018.2 [10.7 kB]
Get:9 http://apt.postgresql.org/pub/repos/apt focal-pgdg/main amd64 postgresql-client-common all 238.pgdg20.04+1 [92.0 kB]
Get:10 http://apt.postgresql.org/pub/repos/apt focal-pgdg/main amd64 postgresql-client-13 amd64 13.6-1.pgdg20.04+1 [1512 kB]
Get:11 http://apt.postgresql.org/pub/repos/apt focal-pgdg/main amd64 postgresql-common all 238.pgdg20.04+1 [229 kB]
Get:12 http://apt.postgresql.org/pub/repos/apt focal-pgdg/main amd64 postgresql-13 amd64 13.6-1.pgdg20.04+1 [15.1 MB]
Fetched 32.1 MB in 6s (5103 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "UTF-8",
	LC_TERMINAL = "iTerm2",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Preconfiguring packages ...
Selecting previously unselected package libcommon-sense-perl.
(Reading database ... 124439 files and directories currently installed.)
Preparing to unpack .../00-libcommon-sense-perl_3.74-2build6_amd64.deb ...
Unpacking libcommon-sense-perl (3.74-2build6) ...
Selecting previously unselected package libjson-perl.
Preparing to unpack .../01-libjson-perl_4.02000-2_all.deb ...
Unpacking libjson-perl (4.02000-2) ...
Selecting previously unselected package libtypes-serialiser-perl.
Preparing to unpack .../02-libtypes-serialiser-perl_1.0-1_all.deb ...
Unpacking libtypes-serialiser-perl (1.0-1) ...
Selecting previously unselected package libjson-xs-perl.
Preparing to unpack .../03-libjson-xs-perl_4.020-1build1_amd64.deb ...
Unpacking libjson-xs-perl (4.020-1build1) ...
Selecting previously unselected package libllvm9:amd64.
Preparing to unpack .../04-libllvm9_1%3a9.0.1-12_amd64.deb ...
Unpacking libllvm9:amd64 (1:9.0.1-12) ...
Selecting previously unselected package libpq5:amd64.
Preparing to unpack .../05-libpq5_14.2-1.pgdg20.04+1_amd64.deb ...
Unpacking libpq5:amd64 (14.2-1.pgdg20.04+1) ...
Selecting previously unselected package pgdg-keyring.
Preparing to unpack .../06-pgdg-keyring_2018.2_all.deb ...
Unpacking pgdg-keyring (2018.2) ...
Selecting previously unselected package postgresql-client-common.
Preparing to unpack .../07-postgresql-client-common_238.pgdg20.04+1_all.deb ...
Unpacking postgresql-client-common (238.pgdg20.04+1) ...
Selecting previously unselected package postgresql-client-13.
Preparing to unpack .../08-postgresql-client-13_13.6-1.pgdg20.04+1_amd64.deb ...
Unpacking postgresql-client-13 (13.6-1.pgdg20.04+1) ...
Selecting previously unselected package ssl-cert.
Preparing to unpack .../09-ssl-cert_1.0.39_all.deb ...
Unpacking ssl-cert (1.0.39) ...
Selecting previously unselected package postgresql-common.
Preparing to unpack .../10-postgresql-common_238.pgdg20.04+1_all.deb ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (238.pgdg20.04+1) ...
Selecting previously unselected package postgresql-13.
Preparing to unpack .../11-postgresql-13_13.6-1.pgdg20.04+1_amd64.deb ...
Unpacking postgresql-13 (13.6-1.pgdg20.04+1) ...
Setting up pgdg-keyring (2018.2) ...
Removing apt.postgresql.org key from trusted.gpg: OK
Setting up libpq5:amd64 (14.2-1.pgdg20.04+1) ...
Setting up libcommon-sense-perl (3.74-2build6) ...
Setting up ssl-cert (1.0.39) ...
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Setting up libtypes-serialiser-perl (1.0-1) ...
Setting up libjson-perl (4.02000-2) ...
Setting up libllvm9:amd64 (1:9.0.1-12) ...
Setting up postgresql-client-common (238.pgdg20.04+1) ...
Setting up libjson-xs-perl (4.020-1build1) ...
Setting up postgresql-client-13 (13.6-1.pgdg20.04+1) ...
update-alternatives: using /usr/share/postgresql/13/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-common (238.pgdg20.04+1) ...
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Adding user postgres to group ssl-cert

Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.
Setting up postgresql-13 (13.6-1.pgdg20.04+1) ...
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Creating new PostgreSQL cluster 13/main ...
/usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/13/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctlcluster 13 main start

update-alternatives: using /usr/share/postgresql/13/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
Processing triggers for systemd (245.4-4ubuntu3.15) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.4) ...



2.2 Connect to postgresql 13 from remote

Now if you try to connect to the pg-13 server from remote ip address, some problems may occur:

The specified database user/password combination is rejected: [28000] FATAL: no pg_hba.conf entry for host "xxxxxxxx", user "kong", database "postgres", SSL on

You should solve the above error by adding following lines to /etc/postgresql/13/main/pg_hba.conf:

# allow remote address
host    all             all             0.0.0.0/0               md5



3. Summary

In this post, I demonstrated how to solve some installation errors of postgresql on ubuntu system 20.0. That’s it, thanks for your reading.