How to Install PostgreSQL on MacBook Pro M1 with Rosetta

Thumbnail

Written by: developervsandhu

Technology and Gadgets

How to Install PostgreSQL on MacBook Pro M1 with Rosetta

The Apple M1 chip offers amazing performance improvements, but some software like PostgreSQL still faces compatibility issues. PostgreSQL is a popular database system used by many developers. On an M1 MacBook, installing PostgreSQL requires Rosetta, Apple's translation layer that enables Intel-based applications to run on M1 devices. In this blog, I'll walk you through the steps to install PostgreSQL on your M1 MacBook Pro.

What is Rosetta?

Rosetta is a dynamic binary translator that allows Intel-based apps to run on Apple Silicon (M1). Since many applications are still optimized for Intel architecture, Rosetta acts as a bridge.

Step 1: Install Rosetta 2

Before installing PostgreSQL, you'll need to install Rosetta if it's not already on your system. Open Terminal and run the following command:

softwareupdate --install-rosetta

Rosetta will now be installed, allowing your Mac to run Intel-based software like PostgreSQL.

Step 2: Install Homebrew

Homebrew is a package manager that simplifies installing and managing software on macOS. If you don't already have Homebrew installed, you can install it with the following command:

`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`

Once installed, run the following command to ensure Homebrew is working correctly:

brew doctor

Step 3: Install PostgreSQL

Now, let’s install PostgreSQL. Normally, you would install PostgreSQL using Homebrew, but due to compatibility issues with M1 chips, we need to run Homebrew under Rosetta.

First, create a new terminal window that runs under Rosetta:

  1. Go to Applications → Utilities.
  2. Right-click on Terminal and select "Get Info."
  3. Check the box labeled "Open using Rosetta."
  4. Open this Rosetta-enabled terminal.

Now, install PostgreSQL by running:

brew install postgresql

This ensures the Intel version of PostgreSQL is installed, which works seamlessly with Rosetta on your M1 MacBook.

Step 4: Start PostgreSQL

Once PostgreSQL is installed, you can start the PostgreSQL service with:

brew services start postgresql

To check if PostgreSQL is running:

pg_ctl -D /usr/local/var/postgres status

You can now access PostgreSQL by running:

psql postgre

Step 5: (Optional) Native M1 Version of PostgreSQL

If you prefer running PostgreSQL natively without Rosetta, you may explore alternatives such as using Docker to run a PostgreSQL container optimized for ARM architecture. While this method bypasses Rosetta, it may add complexity for some users.

Conclusion

Installing PostgreSQL on an M1 MacBook Pro may seem tricky due to the need for Rosetta, but following the steps above should get you up and running. As more software is optimized for Apple Silicon, this workaround may soon become unnecessary. For now, Rosetta is a lifesaver for getting Intel-based applications like PostgreSQL to work on your M1 Mac.

Login To Add Comment

No comments yet.