Follow the PostgreSQL Installation section from the official Fedora Docs but make sure to specify the right version (i.e. 17
) in the first command like below:
sudo dnf install postgresql17-server postgresql17-contrib
The rest of the commands are the same:
sudo systemctl enable postgresql sudo postgresql-setup --initdb --unit postgresql sudo systemctl start postgresql
You must create a new PostgreSQL user with the same name as your OS username to allow Rails application to connect to it automatically without specifying the username
and password
in your database.yml
(see sample file below).
In your terminal, the part before @
is your username but you can also run the whoami
command:
ammar@fedora:~$ whoami
ammar
Login to the psql
session using postgres
user
sudo -u postgres psql
and create a new user with SUPERUSER
privilege (replace ammar
with your username)
postgres=# CREATE USER ammar WITH SUPERUSER;
then list all roles to verify the new user is created.
postgres=# \du
You should also set a password for the postgres
user:
postgres=# \password postgres
and then quit the psql
session.
postgres=# \q
This would allow applications to connect to the PostgreSQL user without a password.
Caution
Do not use this setting in production environment.
Open the config file
sudo nano /var/lib/pgsql/data/pg_hba.conf
and edit the following lines:
host all all 127.0.0.1/32 ident
to host all all 127.0.0.1/32 trust
host all all ::1/128 ident
to host all all ::1/128 trust
Finally, restart the PostgreSQL service:
sudo systemctl restart postgresql
Note
You'll also going to need to install libpq-devel
library to successfully install pg
gem in your Rails application.
sudo dnf install libpq-devel