Installing PostgreSQL
- Windows
- Ubuntu
- macOS
Download the latest version of the PostgreSQL installer for Windows from the official website: https://www.postgresql.org/download/windows/
Run the installer by double-clicking on the downloaded file. The installation process will begin and you will be prompted to select the components you want to install. You can leave the default options selected.
Select the destination folder where you want to install PostgreSQL. You can leave the default option selected.
Select the data directory where you want to store the data files. You can leave the default option selected.
Select the locale for the system environment. You can leave the default option selected.
Choose the password for the postgres user.
Select whether you want to run stack builder at the end of the installation.
Click on the Next button to start the installation process.
Once the installation is complete, click on the Finish button to close the installer.
Now that you have successfully installed PostgreSQL on Windows, you can open the pgAdmin application and connect to the database by providing the password you set during the installation. You can also use command line tools such as psql to connect to the database and perform various operations.
You can also setup the environment variable to use postgres commands from command line without specifying the full path.
Open a terminal window and run the following command to update the package lists:
sudo apt-get update
Install the PostgreSQL package by running the following command:
sudo apt-get install postgresql postgresql-contrib
This command will install the latest version of PostgreSQL and the additional utilities required to manage the PostgreSQL server.
After the installation is complete, you can start the PostgreSQL service by running the following command:
sudo systemctl start postgresql
To make sure that the PostgreSQL service starts automatically on boot, run the following command:
sudo systemctl enable postgresql
Verify that PostgreSQL has been installed successfully by running the following command:
sudo -u postgres psql -c "SELECT version();"
This command will connect to the PostgreSQL server and display the version of PostgreSQL that is currently installed.
(Optional) To set a password for the postgres user, you can run the following command:
sudo -u postgres psql -c "alter user postgres with password 'your_password';"
You can now use the
psql
command-line tool to connect to the PostgreSQL server, create and manage databases, and perform other operations.
Download the PostgreSQL package installer for Mac from the official website: https://www.postgresql.org/download/macosx/
Open the downloaded package file by double-clicking on it. A window will appear with the PostgreSQL installer.
Follow the prompts to install PostgreSQL on your Mac. The installer will guide you through the installation process and install the necessary components.
After the installation is complete, you can use the command line tool psql to connect to the PostgreSQL server and perform various operations.
(Optional) You can also use a GUI based client such as pgAdmin to connect and interact with the server.
(Optional) In order to use the psql command line tool without specifying the full path, you can add the PostgreSQL bin folder to your system's PATH environment variable. You can do this by adding the following line to your
.bash_profile
or.bashrc
file (located in your home directory):export PATH="/Library/PostgreSQL/version/bin:$PATH"