postgreSQL error initdb: command not found

Viewed 53068

i was installing postgresql on ubuntu using linuxbrew:

brew install postgresql

it seems to work fine but after that because i was installing PostgreSQL for the first time i tried creating a database:

initdb /usr/local/var/postgres -E utf8

but it returned as:

initdb: command not found

i tried running the command with sudo but that doesn't helped

5 Answers

I had the same problem and found the answer here.

Ubuntu path is

/usr/lib/postgresql/9.6/bin/initdb

Edit: Sorry, Ahmed asked about linuxbrew, I'm talking about Ubuntu. I Hope this answer helps somebody.

I had a similar issue caused by the brew install postgresql not properly linking postgres. The solve for me was to run:

brew link --overwrite postgresql

you can add the PATH to run from any location

sudo nano ~/.profile

inside nano go to the end and add the following

# set PATH so it includes user's private bin if it exists
if [ -d "/usr/lib/postgresql/14/bin/" ] ; then
    PATH="/usr/lib/postgresql/14/bin/:$PATH"
fi

and configure the alternative

sudo update-alternatives --install /usr/bin/initdb initdb /usr/lib/postgresql/14/bin/initdb 1
Related