How To Install PostgreSQL on Linux Mint 22
In this tutorial, we will show you how to install PostgreSQL on Linux Mint 22. PostgreSQL, often referred to as Postgres, is a powerful, open-source relational database system known for its robustness, scalability, and SQL compliance. It’s widely used for managing large datasets and performing complex queries. Linux Mint 22, a popular Linux distribution, offers a stable and user-friendly environment for developers and database administrators.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of PostgreSQL on Linux Mint 22.
Prerequisites
- A server running one of the following operating systems: Linux Mint 22.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
- At least 1GB of free disk space.
- 2GB or more of RAM (4GB recommended for optimal performance).
- A stable internet connection for downloading packages.
- Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.
Install PostgreSQL on Linux Mint 22
Step 1. Update Your Linux Mint System.
To begin, update your system’s package list to ensure you have the latest versions of all installed software. Open a terminal and run:
sudo apt update sudo apt upgrade
This command refreshes the package index, ensuring that the latest software versions are available for installation.
Step 2. Installing PostgreSQL.
Next, install PostgreSQL along with its additional tools:
sudo apt install postgresql postgresql-contrib
This command installs the core PostgreSQL database server and additional utilities that enhance its functionality. To verify the installation, check the status of the PostgreSQL service:
sudo systemctl status postgresql
You should see an output indicating that PostgreSQL is active and running. If it’s not running, start the service with:
sudo systemctl start postgresql
To ensure PostgreSQL starts automatically on boot, enable the service:
sudo systemctl enable postgresql
Step 3. Configure PostgreSQL.
PostgreSQL is now installed, but some initial configuration is required. First, switch to the postgres
user:
sudo -i -u postgres
Access the PostgreSQL prompt:
psql
Set a password for the postgres
user to secure the database:
\password postgres
You’ll be prompted to enter and confirm the new password. Exit the PostgreSQL prompt:
\q
Step 4. Create a New PostgreSQL Role and Database.
Creating a new role and database is essential for organizing and managing your data. To create a new role, use the following command:
createuser --interactive
You’ll be prompted to enter the name of the new role and whether it should have superuser privileges.
Next, create a new database:
createdb mydatabase
Replace “mydatabase
” with your preferred database name. To grant privileges to the new role, access the PostgreSQL prompt:
psql
Run the following command to grant all privileges on the new database to the role:
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
Replace “mydatabase
” with your database name and “myuser
” with your role name. Exit the PostgreSQL prompt:
\q
Step 5. Configure Remote Access.
By default, PostgreSQL only listens for connections from the local machine. To allow remote access, edit the PostgreSQL configuration file:
sudo nano /etc/postgresql/14/main/postgresql.conf
Find the listen_addresses
line and modify it to:
listen_addresses = '*'
This change allows PostgreSQL to listen for connections on all IP addresses. Next, edit the pg_hba.conf
file to configure client authentication:
sudo nano /etc/postgresql/14/main/pg_hba.conf
Add the following line to allow remote connections:
host all all 0.0.0.0/0 md5
Save and close the file. Restart the PostgreSQL service to apply the changes:
sudo systemctl restart postgresql
Step 6. Installing pgAdmin4.
pgAdmin4 is a popular graphical user interface for managing PostgreSQL databases. Here’s how to install it on Linux Mint 22:
curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
Create a new repository configuration file:
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list'
Update the package list:
sudo apt update
Install pgAdmin4:
sudo apt install pgadmin4
Configure pgAdmin4 by running the setup script:
sudo /usr/pgadmin4/bin/setup-web.sh
Follow the prompts to complete the setup, including setting up an email and password for the admin user.
Step 7. Access pgAdmin4.
To access pgAdmin4, open a web browser and navigate to:
http://localhost/pgadmin4
Log in with the credentials you set during the setup. You can now manage your PostgreSQL databases through the pgAdmin4 interface.
Congratulations! You have successfully installed PostgreSQL. Thanks for using this tutorial to install the latest version of PostgreSQL on the Linux Mint system. For additional help or useful information, we recommend you check the official PostgreSQL website.