DEV Community

Vincent Tommi
Vincent Tommi

Posted on

Installing PostgreSQL on Windows 11 Using the `.exe` Installer: A Guide for Ubuntu Developers

Installing PostgreSQL on Windows 11 Using the .exe Installer: A Guide for Ubuntu Developers

If you've been developing on Ubuntu and recently switched to Windows 11, you might notice that setting up your development environment is slightly different.

On Ubuntu, installing PostgreSQL is straightforward. You can simply open your terminal and execute:

sudo apt update
sudo apt install postgresql postgresql-contrib
Enter fullscreen mode Exit fullscreen mode

But what happens when you're working on Windows?

Unlike Ubuntu, where we commonly use the apt package manager, Windows allows us to install PostgreSQL using a graphical installer (.exe).

In this article, I'll walk you through installing PostgreSQL on Windows 11 using the graphical installer, verifying the installation, and preparing it for use with Laravel.

This guide is intended for beginners and developers transitioning from Ubuntu/Linux to Windows.

1. Download PostgreSQL

First, we need to download PostgreSQL.

Visit the official PostgreSQL website:

Download PostgreSQL for Windows

Select the interactive installer provided by EnterpriseDB (EDB).

Download the appropriate 64-bit installer.

The installer includes several components that make working with PostgreSQL easier.

2. Install PostgreSQL

Once the download is complete:

  1. Locate the downloaded .exe file.
  2. Double-click it to launch the installer.
  3. Click Next.
  4. Choose the installation directory or keep the default location.

Select the installation components

You'll see a list of components available for installation.

For a standard development setup, select:

  • PostgreSQL Server: The database engine responsible for storing and managing data.
  • pgAdmin 4: A graphical interface for managing databases.
  • Command Line Tools: Tools such as psql for interacting with PostgreSQL through the terminal.

Stack Builder is optional. You can skip it for now.

Configure the data directory

The installer will ask you to select a directory where PostgreSQL will store its database files.

You can keep the default directory.

Set your database password

Next, you'll be prompted to create a password for the default PostgreSQL administrative user:

postgres
Enter fullscreen mode Exit fullscreen mode

Remember this password. You'll need it when connecting to your database through pgAdmin, the terminal, or Laravel.

Configure the port

PostgreSQL uses port 5432 by default.

Keep the default port unless another PostgreSQL instance is already using it.

Continue with the default locale and complete the installation.

That's it! PostgreSQL should now be installed on your Windows machine.

3. Verify the PostgreSQL Installation

After installation, let's confirm that PostgreSQL is accessible from the command line.

Open Command Prompt (CMD).

Press:

Windows + R
Enter fullscreen mode Exit fullscreen mode

Type cmd and press Enter.

Execute:

psql --version
Enter fullscreen mode Exit fullscreen mode

If everything is configured correctly, you'll see output similar to:

psql (PostgreSQL 18.x)
Enter fullscreen mode Exit fullscreen mode

The version number will depend on the version you installed.

What if 'psql is not recognized'?

You might encounter this error:

'psql' is not recognized as an internal or external command,
operable program or batch file.
Enter fullscreen mode Exit fullscreen mode

Don't panic. This doesn't necessarily mean PostgreSQL failed to install.

It usually means Windows cannot locate the PostgreSQL executable because its installation directory hasn't been added to the system PATH.

To fix this:

  1. Search for Environment Variables in the Windows Start menu.
  2. Select Edit the system environment variables.
  3. Click Environment Variables.
  4. Under System variables, find and select Path.
  5. Click Edit, then New.
  6. Add your PostgreSQL bin directory.

For example:

C:\Program Files\PostgreSQL\18\bin
Enter fullscreen mode Exit fullscreen mode

Replace 18 with your installed PostgreSQL version.

  1. Click OK to save your changes.
  2. Close and reopen CMD.

Now run:

psql --version
Enter fullscreen mode Exit fullscreen mode

Windows should now recognize the command.

4. Open pgAdmin 4

PostgreSQL comes with pgAdmin 4, a graphical database management tool.

Search for pgAdmin 4 in the Windows Start menu and open it.

When prompted, enter the password you created during installation.

You'll see your PostgreSQL server in the browser panel.

From here, you can:

  • Create and manage databases.
  • Execute SQL queries.
  • View database tables.
  • Manage database users.
  • Inspect database relationships.

For beginners, pgAdmin provides a convenient way to understand how PostgreSQL works without relying entirely on terminal commands.

5. Create a Database

Before connecting PostgreSQL to Laravel, let's create a database.

Inside pgAdmin:

  1. Expand your PostgreSQL server.
  2. Right-click Databases.
  3. Select Create → Database.
  4. Enter the database name:
laravel_pos
Enter fullscreen mode Exit fullscreen mode
  1. Keep postgres as the owner.
  2. Click Save.

Your database is now ready.

6. Connect PostgreSQL to Laravel

If you already have a Laravel project, open its .env file.

Locate the database configuration section and update it as follows:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel_pos
DB_USERNAME=postgres
DB_PASSWORD=your_postgres_password
Enter fullscreen mode Exit fullscreen mode

Replace your_postgres_password with the password you created during PostgreSQL installation.

Let's understand these configuration values:

Variable Description
DB_CONNECTION Database driver Laravel will use
DB_HOST Address of the PostgreSQL server
DB_PORT PostgreSQL connection port
DB_DATABASE Name of the database
DB_USERNAME PostgreSQL username
DB_PASSWORD PostgreSQL password

Notice that we're using pgsql instead of mysql.

This tells Laravel to use PostgreSQL as its database driver.

7. Test the Laravel Connection

After updating your .env file, open your Laravel project in the terminal.

First, clear the cached configuration:

php artisan config:clear
Enter fullscreen mode Exit fullscreen mode

Then execute:

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

If the connection is successful, Laravel should execute the database migrations against your PostgreSQL database.

If you encounter connection errors, check the following:

  • Is the PostgreSQL service running?
  • Did you enter the correct database password?
  • Does the database laravel_pos exist?
  • Are you using the correct port (5432)?
  • Are the PHP PostgreSQL extensions pdo_pgsql and pgsql enabled?

Ubuntu vs Windows: What Changes?

For developers transitioning from Ubuntu to Windows, here's a quick comparison:

Task Ubuntu Windows 11
Install PostgreSQL apt install postgresql EDB .exe installer
Open terminal Ctrl + Alt + T CMD / PowerShell
Manage databases Terminal / pgAdmin Terminal / pgAdmin
Default PostgreSQL port 5432 5432
Configure environment variables Shell configuration Windows Environment Variables

The installation process is different, but the PostgreSQL concepts remain the same.

Final Thoughts

Moving from Ubuntu to Windows doesn't mean you have to abandon the development tools and technologies you're familiar with.

PostgreSQL works on both operating systems, and once installed, you can manage your databases using the same SQL commands and database concepts.

As developers, learning to work across different environments is part of the journey.

If you're also transitioning from Ubuntu to Windows, take your time to understand how the new environment works. You don't have to learn everything in one day.

Keep learning, keep building, and keep experimenting.

Have you recently moved from Ubuntu/Linux to Windows? What challenges have you encountered while setting up your development environment?

Top comments (0)